Monday 25 April 2016

Python Practice Assignments 2

Yay more practice assignments before the test!

1.  Create a calculator that can add, subtract, multiply or divide.
·         First it will ask you what calculator function you want.
·         Then it asks you for the 1st number.
·         It asks you for the 2nd number
·         It prints the formula and the answer in one line
·         It will ask you if you want to go again.  Entering n will exit and it will say "Bye!"
·         The output should look like below:

This can be done in 18 lines!

2.  Create a math quiz game with 5 questions which will tell you your mark and percentage at the end!
·         It will ask all 5 questions first
·         It will tell you what you got out of 5.  Then it will tell you what your percentage is.
·         You output should look like the following:

The last line is:         print "You got ", score*100/5, "%!"
This can be done in 18 lines and fast with a bunch of copy and paste!
3.  Create a lottery game that allows you to pick a number from 1 to 100 for $1.
·         First it tells you that you have $50.
·         Then it asks you how many tickets you would like to buy for $1 each. 
·         If the user enters more than 50 tickets, it asks them to pick again!
·         Then it gives you that many random numbers from 1 to 100.  The numbers can be the same.
·         It picks a random number.  If you have a ticket that matches the number, you win $100! Otherwise, you lose. (Note: you can pick a random number at any time in the program)
·         It will totally your money at the end (win or lose)
·         It will ask you if you want to play again, keeping the same value of money for the next game
The output will look like this:

This can be done in 27 lines!
4.  Create your own program that you think should be on the test.
Include instructions similar to those given in class and an answer.
The program should include 4 of the following elements:
1.       raw_input
2.       input
3.       for loop
4.       while loop
5.       random
6.       if , elif and else

The program answer should be no longer than 30 lines of code.  Email it by Friday at 9pm!

No comments:

Post a Comment