-
Notifications
You must be signed in to change notification settings - Fork 0
Home
- Create a program that inputs and displays the name and complete mailing address formatted in the manner that you would usually see on the outside of an envelope.
Ans 1
a, b, d, e, f = input('Name : '), input('Address : '), input('Location : '), input('Pincode : '), input('Country : ') def personal_details(): print("Name: %s\nAddress: %s\nLocation: %s\nPincode: %s\nCountry: %s"% (a, b, d,e,f)) personal_details()
- Write a program that asks the user to enter his or her name. The program should respond with a message that says hello to the user, using his or her name.
Ans 2.
def personal_details(): name =str(input("Enter Name :")) print ("Hello",name) personal_details()
- Write a program that asks the user to enter the width and length of a room. Once the values have been read, your program should compute and display the area of the room. The length and the width will be entered as floating point numbers. Include units in your prompt and output message; either feet or meters, depending on which unit you are more comfortable working with.
Ans 3.
length = float (input ("Enter the length of the room in feet: ")) width = float (input ("Enter the width of the room in feet: "))
area = length * width
print ("The area of the room is", area, "square feet")
- Create a program that reads the length and width of a farmer’s field from the user in feet. Display the area of the field in acres.
Ans 4.
SQFT_PER_ACRE = 43560
length = float (input ("Enter the length of the field in feet: ")) width = float (input ("Enter the width of the field in feet: "))
acres = length * width / SQFT_PER_ACRE
print ("The area of the field is", acres, "acres")
- In many jurisdictions a small deposit is added to drink containers to encourage people to recycle them. In one particular jurisdiction, drink containers holding one liter or less have a $0.10 deposit, and drink containers holding more than one liter have a $0.25 deposit. Write a program that reads the number of containers of each size from the user. Your program should continue by computing and displaying the refund that will be received for returning those containers. Format the output so that it includes a dollar sign and always displays exactly two decimal places.
LESS_DEPOSIT = 0.10 MORE_DEPOSIT = 0.25
less = int (input ("How many containers 1 litre or less? ")) more = int (input ("How many containers more than 1 litre? "))
refund = less * LESS_DEPOSIT + more * MORE_DEPOSIT
print ("Your total refund will be $%.2f." % refund)
- The program that you create for this exercise will begin by reading the cost of a meal ordered at a restaurant from the user. Then your program will compute the tax and tip for the meal. Use your local tax rate when computing the amount of tax owing. Compute the tip as 18 percent of the meal amount (without the tax). The output from your program should include the tax amount, the tip amount, and the grand total for the meal including both the tax and the tip. Format the output so that all of the values are displayed using two decimal places.
Ans 6.
TAX_RATE = 0.05 TIP_RATE = 0.18
cost = float (input ("Enter the cost of the meal: "))
tax = cost * TAX_RATE tip = cost * TIP_RATE total = cost + tax + tip
print("\nTip: ", format(tip, '8.2f')) print("Sales tax:", format(tax, '8.2f')) print("Total: ", format(total, '8.2f'))
- Write a program that reads a positive integer, n, from the user and then displays the sum of all of the integers from 1 to n. The sum of the first n positive integers can be computed using the formula: sum = [(n)(n + 1)]/2
Ans 7
#Calculate the sum of first N positive integers.
#Read the input from the user n = int(input("Enter a positive integer: "))
#Calculate the sum total = n * (n+1) / 2
#Display the result print("The sum of the first",n,"positive integers",total)
- An online retailer sells two products: widgets and gizmos. Each widget weighs 75 grams. Each gizmo weighs 112 grams. Write a program that reads the number of widgets and the number of gizmos in an order from the user. Then your program should compute and display the total weight of the order.
Ans 8
numOfWidgets = input ("Enter your number of widgets: ") numofGizmos = input ("Enter your number of Gizmos: ")
converts1 = int(numOfWidgets) # converts number of widgets into an integer convert2 = int(numofGizmos) # converts number of gizmos into an integer
weightOfWidgets = converts1 * 75 weightOfGizmos = convert2 * 112
totalWeight = weightOfGizmos + weightOfWidgets
convert3 = str(totalWeight) print ("") # prints an empty line print ("The total weight of the order is " + convert3)
- In the United States, fuel efficiency for vehicles is normally expressed in miles-per- gallon (MPG). In Canada, fuel efficiency is normally expressed in liters-per-hundred kilometers (L/100 km). Use your research skills to determine how to convert from MPG to L/100 km. Then create a program that reads a value from the user in American units and displays the equivalent fuel efficiency in Canadian units.
ANS 9
#Read the MPG input values from the user
m = float(input ("Enter the value of m: ")) def convert_mileage(m): #return (282.5 / m ) return (236.5 / m ) if name == 'main' : print (" MPG = ",convert_mileage(m)," Liters per 100 kilometers") #print ("Liters per 100 kilometers = ",convert_mileage(m),"MPG ")
- Create a program that reads two integers, a and b, from the user. Your program should compute and display:
• The sum of a and b • The difference when b is subtracted from a • The product of a and b • The quotient when a is divided by b • The remainder when a is divided by b
Ans 10
a = int (input ("Enter the value of a: ")) b = int (input ("Enter the value of b: "))
print (a, "+", b, "is", a + b)
print (a, "-", b, "is", a - b)
print (a, "", b, "is", a * b)
# *
print (a, "/", b, "is", a / b) print (a, "%", b, "is", a % b)