Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 1. Write the program to determine how much to tip the server in a restaur

ID: 3920588 • Letter: P

Question

Python

1.   Write the program to determine how much to tip the server in a restaurant. The tip should be 15% of the bill, with a minimum of $2.

2.   A copy center charges 5 cents per copy for the first 100 copies and 3 cents per copy for each additional copy. Write a program that requests the number of copies as input and displays the total cost.

3.   Federal law requires that hourly employees be paid “Time and a half” for work in excess of 40 hours in a week. For example, if a person’s hourly wage is $ 12 and he/ she works 60 hours a week, the person’s gross pay should be

             (40 * 12) + (1.5 * 12* (60 – 40)) = $840

4.   Write the Python Code for the Celsius and Fahrenheit Converter.

5.   Display the table of numbers and the square.

6.   Develop the code to find the minimum, maximum and average of a sequence of non- negative numbers entered by the user. The user is told to enter the number -1 to indicate the end of data entry.   

7.   Display the simple menu options to show the facts about the United States. For example, option 1: Capital, 2: National Bird, 3: National flower, 4. Do you like to repeat?

8.   Demonstrate how two strings can be compared with the “<” operator. Get two names from the user and display the names in alphabetical order.

9.   Create a drawing panel and the graphical pen to represent the rectangle and an oval. Use your own dimensions. Fill the rectangle with “blue” and oval with “green” color.

10.                  With the proper code, methods and functions, open a text file called “input.txt”, read the contents of it and print it onto the screen.

Explanation / Answer

Screenshot

Program

#1.Write the program to determine how much to tip the server in a restaurant.
# The tip should be 15% of the bill, with a minimum of $2.
bill=input('Enter the bill amount:')
tip=float(bill)*.15
if tip<2:
    tip=2
print('Tip of the bill $',bill,'= $',tip)
#2.A copy center charges 5 cents per copy for the first 100 copies
#and 3 cents per copy for each additional copy.
#Write a program that requests the number of copies as input and displays the total cost.
copies=input('Enter the number of copies:')
if int(copies)<=100:
    charge=int(copies)*5
    if charge==100:
        print('Charge to copy ',copies,'= $',1)
    elif charge>100:
        dollar=int(charge/100)
        cent=charge%100
        print('Charge to copy ',copies,'= ',dollar,'dollar and ',cent,'cents')
    else:
        print('Charge to copy ',copies,'= ',charge,'cents')
else:
    charge=500+(int(copies)-100)*3
    dollar=int(charge/100)
    cent=charge%100
    print('Charge to copy ',copies,'= ',dollar,'dollar and ',cent,'cents')
#3.Federal law requires that hourly employees be paid “Time and a half” for work in excess of 40 hours in a week.
# For example, if a person’s hourly wage is $ 12 and he/ she works 60 hours a week, the person’s gross pay should be
#(40 * 12) + (1.5 * 12* (60 – 40)) = $840
hrs=input('Enter the number of hours worked an employee: ')
if(int(hrs)>40):
    sal=(40 * 12)+(1.5*12*(int(hrs)-40))
    print('Salary= $',sal)
else:
    sal=(int(hrs) * 12)
    print('Salary= $',sal)
#4.Write the Python Code for the Celsius and Fahrenheit Converter.
celcius=input('Enter temperature in celcius: ')
fahrenheit=float(celcius)*9/5+32
print('Temperature in degrees ',celcius,'=',fahrenheit,'F')
#5.Display the table of numbers and the square.
number=input('Enter the number to display square:')
i=0
print('Numbers    Squares')
while i<int(number):
    print('{:<10}'.format(i+1),(i+1)*(i+1))
    i+=1
#6.Develop the code to find the minimum, maximum and average of a sequence of non- negative numbers entered by the user.
#The user is told to enter the number -1 to indicate the end of data entry.
userInput=[]
userInputPositive=[]
avg=0.0
min=0
max=0
val=int(input("Enter a number: "))
while(val!=-1):
    userInput.append(val)
    val=int(input("Enter a number: "))
for elem in userInput:
    if elem>0:
        userInputPositive.append(elem)
min=userInputPositive[0]
max=userInputPositive[0]
for elem in userInputPositive:
    avg+=elem
    if min>elem:
        min=elem
    if max<elem:
        max=elem
print('Minimum=',min)
print('Maximum=',max)
print('Average=',(avg/len(userInputPositive)))
#8.Demonstrate how two strings can be compared with the “<” operator.
#Get two names from the user and display the names in alphabetical order.
str1=input("Enter first string: ")
str2=input("Enter second string: ")
if str1<str2:
    print(str1)
    print(str2)
else:
    print(str2)
    print(str1)

---------------------------------------------------