Exercise
2.1 – Write the program that raw_input() function to prompt a user for their
name and then welcomes them.
>>>name = raw_input(“Enter your name: “) Enter your name: James >>>print “Hello “ + name Hello James
Exercise
2.2 – Write a program to prompt the user for hours and rate per hour to compute
monthly paycheck.
>>>hours = raw_input(“Enter hours: “) Enter hours: 35 >>>payrate = raw_input(“Enter rate: “) Enter Rate: 2.75 >>>paycheck = int(hours)*int(rate) >>>print “Pay: “ + str(paycheck) 96.25
Exercise
2.3 – Assume that we execute the follow assignment statements:
Width
= 15
Height
= 12.0
For
each of the following expressions, write the value of the expression and the
type
- width/2
- width/2.0
- height/3
- 1+2*5
>>>width = 15 >>>height = 12.0 >>>a=width /2 >>>print a 7 >>> type(a) >>>b = width/2.0 >>>print b 7.5 >>>type(b)>>>c = height/3 >>>print c 4.0 >>>type(c) >>>d=1+2*5 >>>print d 11
Exercise
2.5 - Write a program which prompts the user for a Celsius temperature, convert
the temperature to Fahrenheit and print out the converted temperature.
>>>deg=raw_input(“Enter a temperature in degrees Celsius: “) Enter a temperature in degrees Celsius: 100 >>>TC = int(deg) >>>TF = 9/5.0 * TC + 32 >>>print TF 212.0
Nema komentara:
Objavi komentar