Skip to content

josienb/python_exercises

Repository files navigation

Python Exercises

Some practice exercises in Python.

Grading Program

Exercise source: http://www.cplusplus.com/forum/articles/12974/
Requires:

  • variables, data types, and numerical operators
  • basic input/output
  • logic (if statements, switch statements)

Write a program that allows the user to enter the grade scored in a programming class (0-100). If the user scored a 100 then notify the user that they got a perfect score.

  1. Modify the program so that if the user scored a 90-100 it informs the user that they scored an A
  2. Modify the program so that it will notify the user of their letter grade 0-59 F 60-69 D 70-79 C 80-89 B 90-100 A

Cola Machine

Exercise source: http://www.cplusplus.com/forum/articles/12974/
Requires:

  • variables, data types, and numerical operators
  • basic input/output
  • logic (if statements, switch statements)

Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever). Then allow the user to choose a beverage by entering a number 1-5. Output which beverage they chose.

  1. If you program uses if statements instead of a switch statement, modify it to use a switch statement. If instead your program uses a switch statement, modify it to use if/else-if statements.
  2. Modify the program so that if the user enters a choice other than 1-5 then it will output "Error. choice was not valid, here is your money back."

While( user == gullible )

Exercise source: http://www.cplusplus.com/forum/articles/12974/
Requires:

  • variables, data types, and numerical operators
  • basic input/output
  • logic (if statements, switch statements)
  • loops (for, while, do-while)

Write a program that ccontinues to asks the user to enter any number other than 5 until the user enters the number 5. Then tell the user "Hey! You weren't supposed to enter 5!" and exit the program.

  1. Modify the program so that after 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient than I am, you win." and exit.

  2. Modify the program so that it asks the user to enter any number other than the number equal to the number of times they've been asked to enter a number. (i.e on the first iteration "Please enter any number other than 0" and on the second iteration "Please enter any number other than 1" etc. etc. The program must behave accordingly exiting when the user enters the number they were asked not to.)

Pancake Glutton

Exercise source: http://www.cplusplus.com/forum/articles/12974/
Requires:

  • variables, data types, and numerical operators
  • basic input/output
  • logic (if statements, switch statements)
  • loops (for, while, do-while)
  • arrays

Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10). Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.

  1. Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.

  2. Modify the program so that it outputs a list in order of number of pancakes eaten of all 10 people, i.e.:

  • Person 4: ate 10 pancakes
  • Person 3: ate 7 pancakes
  • Person 8: ate 4 pancakes
  • ...
  • Person 5: ate 0 pancakes

Bracketing Search

Exercise source: http://www.cplusplus.com/forum/articles/12974/
Requires:

  • variables, data types, and numerical operators
  • basic input/output
  • logic (if statements, switch statements)
  • loops (for, while, do-while)
  • psudo random numbers

Write a program that calculates a random number 1 through 100. The program then asks the user to guess the number. If the user guesses too high or too low then the program should output "too high" or "too low" accordingly. The program must let the user continue to guess until the user correctly guesses the number.

  1. Modify the program to output how many guesses it took the user to correctly guess the right number.

  2. Modify the program so that instead of the user guessing a number the computer came up with, the computer guesses the number that the user has secretely decided. The user must tell the computer whether it guesed too high or too low.

  3. Modify the program so that no matter what number the user thinks of (1-100) the computer can guess it in 7 or less guesses.

About

Some practice exercises in Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages