Stanford Python Camp D – 1, 2

Share:

D-1: Learning about the parts and their functions of a computer

D – 1 Notes
D – 1 Notes

D-2: Using the “print” and “input” command and learning about the Python operators

Assignment 2 – A. Nametag

At a certain conference, each delegate has to wear a tag showing his name and the organization they represent. Prompt the user to enter the name and organization. Write a program to print the following nametag.

####################################################################### ### ANNUAL CONFERENCE ### ####################################################################### ### NAME: John Smith ### ### ### ####################################################################### ### ORGANIZATION: Stanford University ### ### ### #######################################################################

Assignment 2 – A code
Assignment 2 – A outcome

Assignment 2 – B. Distance between two points

The distance between two points (x1, y1) and (x2, y2) on a Cartesian coordinate plane is given by the equation

D=sqrt((x1–x2)2 +(y1–y2)2)

Write a program to calculate the distance between any two points (x1, y1) and (x2, y2) specified by the user. Use good programming practices in your program. Use the program to calculate the distance between (2, 3) and (8, -5).

Assignment 2 – B code
Assignment 2 – B outcome

Assignment 2 – C. Circle

Write a program that prompts the user for a radius r, and then prints

  • The area and circumference of a circle with that radius.
  • The volume and surface area of a sphere with that radius.

Test the results of your program for a circle and sphere with a radius of 7.5.

Assignment 2 – C code
Assignment 2 – C outcome

Assignment 2 – D. Change Calculator

Write a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive. Note: This can be solved by using the %, and // operators sequentially.

In the following example, if Amount due = $ 6.13 Amount paid = $ 10.00 The program should print the following:

Change due = $ 3.73 Number of dollars = 3 Number of quarters = 2 Number of dimes = 2 Number of nickels = 0 Number of pennies = 3

Assignment 2 – D code
Assignment 2 – D outcome

Stay In Touch.

  • kimhannah2005@gmail.com