PYTHON PROGRAMMING QUESTIONS WITH IF-ELSE 1. Take values of length and breadth of a rectangle from user and check if it is square or not. 2. Take two int values from user and print greatest among...

1 answer below »
Copy-past your code and output to a word document


PYTHON PROGRAMMING QUESTIONS WITH IF-ELSE 1. Take values of length and breadth of a rectangle from user and check if it is square or not. 2. Take two int values from user and print greatest among them. 3. A shop will give discount of 10% if the cost of purchased quantity is more than 1000. Ask user for quantity Suppose, one unit will cost 100. Judge and print total cost for user. 4. A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years. Ask user for their salary and year of service and print the net bonus amount. 5. Write a program to print absolute vlaue of a number entered by user. E.g.- INPUT: 1 OUTPUT: 1 INPUT: -1 OUTPUT: 1 6. Write a program to display "Hello" if a number entered by user is a multiple of five , otherwise print "Bye".
Answered Same DayApr 09, 2021

Answer To: PYTHON PROGRAMMING QUESTIONS WITH IF-ELSE 1. Take values of length and breadth of a rectangle from...

Pratap answered on Apr 09 2021
147 Votes
1. Take values of length and breadth of a rectangle from user and check if it is square or not.
Program:
"""
Rectangle-Square Verification Program
Program will ask user for rectangle dimensions
and verifies whether the figure is rectangle
or a square
"""
def user_query():
"""Function to interact with the user"""
try:
#ask the user to enter length of the rectangle
length = int(input("Enter length of the rectangle: "))
#ask the user to enter breadth of the rectangle
breadth = int(input("Enter breadth of the rectangle: "))
#compare length and breadth of the rectangle
#is greater than zero or not
if length <= 0 or breadth <= 0:
     print("Length and breadth are invalid!")
return None, None
else:
return length, breadth
except:
#handle exception in case of invalid input type
print("Invalid input type!")
return None, None
def execution():
"""Main function of the program
which performs comparison and displays the result"""
#length - length of the rectangle
#breadth - breadth of the rectangle
#get user inputs for length and breadth
length, breadth = user_query()
#recursively ask user for input till
#valid positive length and breadth is recieved
while length is None or breadth is None:
length, breadth = user_query()
if length == breadth:
#length is equal to breadth for a square
print("The figure is a square.")
else:
#length & breadth are not equal for non-square figure
print("The figure is not a square.")
if __name__ == "__main__":
execution()
#Ed of program
Output:
Io_1:
Enter length of the rectangle: 5
Enter breadth of the rectangle: 5
The figure is a square.
Io_2:
Enter length of the rectangle: 5
Enter breadth of the rectangle: 6
The figure is not a square.
Io_3:
Enter length of the rectangle: 5
Enter breadth of the rectangle: -4
Length and breadth are invalid!
Enter length of the rectangle: 5
Enter breadth of the rectangle: 7
The figure is not a square.
2. Take two int values from user and print greatest among them.
Program:
"""
Greatest of Integers Program
Program will get two integers
by the user and print the greatest
"""
def user_input():
"""Function to interact with the user"""
try:
#get two integers int_1 & int_2 from user
int_1 = int(input("Enter first integer: "))
int_2 = int(input("Enter second integer: "))
#return both integers
return int_1, int_2
except:
#handle invalid input type
print("Invalid input type!")
return None, None
def execution():
"""Main function which does the execution
gets the input, compares
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here