Python Lesson 3 Exercises -- Strings, Math and Variables
Write each script described below. Save each script in your folder as "pa3-1", "pa3-2", and so forth. Run the script to make sure it works. Remember to include comments that contain your name and a description of the script you have written in the first two lines of code.
Exercise 1:
Create a script that uses a variable and will write 100 times "I will not talk in class." Make each sentence on a separate line.
Exercise 2:
Create a script that will ask for a users first name, middle name, and last name, then print out their full name on a line along with a salutation, i.e. "Hello Jed Clampett".
NOTE: To allow the user to input their name, set the variable equal to raw_input("Prompt: ").
Example: first_name = raw_input("What is your first name: ")
Exmaple: dog = raw_input("What is the name of your dog? ")
Exercise 3:
Create an adding machine that will ask the user for two numbers then add them together and show the result.
NOTE: To allow numerical inputs, set the variable equal to input("Prompt")
Example: first_number = input("Enter first number: ")
Example: days = input("How many days? ")
Exercise 4:
Create a division machine that will ask the user for two numbers then divide and give the result. The program should give the result in two parts: the whole number dividend and the remainder.
Example: If a user enters 10 / 4, the computer should give the result 2 Remainder 2.
Exercise 5:
Create a script that will convert Celsius to Fahrenheit. The program should ask the users to enter the temperature in Celsius and should print out the temperature in Fahrenheit. Use the equation F= (9/5)*C + 32.
Exercise 6:
Create a script that will convert Fahrenheit to Celsius. The program should ask users to enter the temperature in Fahrenheit and should print out the temperature in Celsius. Use the equation C = (5/9)(F - 32)
Exercise 7:
Write a script that will ask the user for the radius of a circle, then will calculate and display the area and circumference of the circle.(Note: To use the builtin "pi" variable, make sure the first line of your code says "from math import pi")
Exercise 8:
Write a Mad-Libs style program. The program will ask the user for specific types of words (colors, verbs, nouns, names, etc.) then print a story using the words entered by the user.
** Extra Credit **
You will receive 5 points extra credit for any other metric conversion or geometric calculation scripts you write. Print out the code for these scripts and turn it in. Make sure the code has your name in the comments at the top, along with a description of what the script does.
Restricted access |