Programming for Everybody (Getting Started with Python) -all weeks assignment solutions
It is recommended that you should solve the assignment and quiz by yourself honestly then only it makes sense to complete the course.
but if you cant figure out some part of it than you can refer these solutions
make sure you understand the solution
dont just copy paste it
--------------------------------------
Week 3 - Assignment Write hello world
# the code below almost works
print "hello world"
Week 4 - Assignment 2.2
# The code below almost works
name = raw_input("Enter your name")
print "Hello", name
Enter your nameSarah Hello Sarah
Week 4 - Assignment 2.3
# This first line is provided for you
hrs = float(raw_input("Enter Hours:"))
rph = float(raw_input("Enter rate per hour"))
print hrs*rph
Week 5 - Assignment 3.1
hrs = raw_input("Enter Hours:")
h = float(hrs)
rph = float(raw_input("Enter rate per hour"))
if hrs > 40:
print 40*rph + (h-40)*rph*1.5
else:
print h*rph
Week 5 - Assignment 3.3
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table:
Score Grade
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
< 0.6 F
If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85.
score = float(raw_input("Enter Score: "))
if(score>1.0):
print ("out of range")
elif score >= 0.9:
print ("A")
elif score >= 0.8:
print ("B")
elif score >= 0.7:
print ("C")
elif score >= 0.6:
print ("D")
elif score < 0.6:
print ("F")
B
Week 6- Assignment 4.6
Write a program to prompt the user for hours and rate per hour using input to compute gross pay.
Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours.
Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation.
The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75).
You should use input to read a string and float() to convert the string to a number.
Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly.
Do not name your variable sum or use the sum() function.
def computepay(h,r):
if h>40:
rate1 = (r*1.5)*(h-40)
return ((h-5)*r)+rate1
hrs = float(raw_input("Enter Hours:"))
rate = float(raw_input("Enter Rate:"))
p = computepay(hrs,rate)
print (p)
Week 7- Assignment 5.2
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'.
Once 'done' is entered, print out the largest and smallest of the numbers.
If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message
and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done": break
try:
num = int(num)
if largest is None or largest < num: largest = num
if smallest is None or smallest > num: smallest = num
except:
print ("Invalid input")
continue
print ("Maximum is",largest)
print ("Minimum is",smallest)
reference :coursera.org
No comments