120x Filetype PDF File size 0.34 MB Source: cf.linnbenton.edu
CS160 Python Programming Assignment Fall 2018 Instructions A. There are two “modes” of coding in Python: interactive mode and script mode (your instructor has demonstrated these two modes to you). Write scripts for all the exercises below. However, you should take advantage of interactive mode to explore ideas and try out small snippets of code. B. Open your Google Drive and inside the folder you’ve shared with your instructor create a new folder named Python Project. You’ll upload your Python script files to this folder just as you’ve previously done. C. Use the python.org website (try the tutorial) to help you with this project. Don’t be afraid to google things, professional programmers do it every single day! D. Start each script file with a comment containing your name and an outline, or pseudocode, for how you plan to approach the problem. Use comments throughout your program as needed to explain or clarify what you’re doing in your code. E. You do not need to complete all the following exercises to get a passing grade on this project. Take your best shot at each. Be sure to comment your code and explain how (you think) the program is working as you go. Partial credit will be awarded for programs that are well documented with comments explaining their operation even if they do not function properly. F. You are also welcome to work collaboratively on the project, both in and out of the classroom. If you work with other students, please put their names in the comments at the top of your script file. That will help me understand what happened if I see very similar code. Good luck and have fun!! Page 1 of 13 Exercise 1 – Dice Roller Write a program that will roll dice for the user. Ask the user how many dice they want to roll and how many sides each die should have (all dice in any given roll will have the same number of sides). Display the individual rolls and their sum for the user. Save your script in a file named dice_roller.py. A sample run is shown below. Note, your output doesn’t have to match the sample exactly, it is there to give you an idea of what your program should produce. Page 2 of 13 Exercise 2 – Guess the Number Your program will first randomly generate a number between 1 and 100, inclusive. This number should be unknown to the user who will then try to guess what it is. If the user’s guess is wrong, the program should return some sort of indication as to how it is wrong (e.g. the number is too high or too low). If the user guesses correctly, a positive indication should appear. You’ll need to check if the user’s input is an actual number (your first error-catching code!); to see the difference between the inputted number and the randomly generated numbers, and to then compare the numbers. Save your program in a file named guessing_game.py. A sample run is shown below. Note, your output doesn’t have to match the sample exactly, it is there to give you an idea of what your program should produce. Page 3 of 13 Exercise 3 – Rock, Paper, Scissors Write a Python program that plays a game of rock, paper, scissors with the user. Your program should prompt the user for their play, randomly generate its own, then announce a winner. Your program should keep a running tally of the user’s wins and losses and ask if they want to play again, starting a new game if they say “yes.” Save your program in a file named rock- paper-scissors.py. A sample run is shown below. Note, your output doesn’t have to match the sample exactly, it is there to give you an idea of what your program should produce. Exercise 4 – Mad Libs Generator The program will first prompt the user for a series of inputs, a la Mad Libs. For example, a singular noun, an adjective, etc. Then, once all the information has been inputted, the program will take that data and place them into a premade story template. You’ll need prompts for user input, and to then print out the full story at the end with the input included. Save your program in a file named madlibs.py. Exercise 5 – FizzBuzz Write a Python program which iterates over the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Save your program in a file named fizzbuzz.py. Page 4 of 13
no reviews yet
Please Login to review.