Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Similar documents
Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Problem 1.1 (3 pts) :Python uses atomic data types and builds up from there. Give an example of: a. an int b. a double c. a string

CONDITION CONTROLLED LOOPS. Introduction to Programming - Python

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

Lab 4: Strings/While Loops Due Sun, Apr 17 at midnight

Lab 4: Strings/Loops Due Apr 22 at midnight

Introduction to Computer Science Unit 3. Programs

Here is a sample IDLE window illustrating the use of these two functions:

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

(Python) Chapter 3: Repetition

Lab 4: Due Sunday, Nov 22

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Decisions, Decisions. Testing, testing C H A P T E R 7

Introduction to Computer Science Unit 4B. Programs: Classes and Objects

15-110: Principles of Computing, Spring 2018

How To Think Like A Computer Scientist, chapter 3; chapter 6, sections

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

JS Lab 1: (Due Thurs, April 27)

The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion - Python version

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression

Condition Controlled Loops. Introduction to Programming - Python

Programming with Python

CS 051 Homework Laboratory #2

Lab 4 Due April 18 th

What you get When you install Python for your computer, you get a number of features:

Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

Programming Project 1

6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module.

Intro. Scheme Basics. scm> 5 5. scm>

[ the academy_of_code] Senior Beginners

Text Input and Conditionals

Using IDLE for

15-110: Principles of Computing, Spring 2018

Honors Computer Science Python Mr. Clausen Program 7A, 7B

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list?

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

Midterm Exam 2B Answer key

Animations involving numbers

CPSC 217 Assignment 3

CISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab)

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS1110 Lab 6 (Mar 17-18, 2015)

Midterm #1 Fall minutes

Introduction to Programming with JES

Invent Your Own Computer Games with Python

The little book of programming challenges

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

CS 150 Lab 10 Functions and Random Numbers

mith College Computer Science Lecture Notes CSC111 Week 7 Spring 2018 Dominique Thiébaut

cs1114 REVIEW of details test closed laptop period

CS 142 Style Guide Grading and Details

Table of Laplace Transforms

Introduction to Java Programs for Packet #4: Classes and Objects

CMPSCI 119 LAB #2 Anime Eyes Professor William T. Verts

Software Development Pseudocode

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

LOOPS. Repetition using the while statement

6.149 Checkoff 2. What to complete. Recall: Creating a file and running a program in IDLE.

Computer and Programming: Lab 1

CS 111X - Spring Final Exam - KEY

CPSC 217 Midterm (Python 3 version)

Noughts and Crosses. Step 1: Drawing the grid. Introduction

CMSC 201 Spring 2017 Lab 05 Lists

Second Examination Solution

Structure and Interpretation of Computer Programs

Procedures: Algorithms and Abstraction

Notebook Assignments

CMSC201 Computer Science I for Majors

Lecture 3. Input, Output and Data Types

Othello Turtle Extra Credit (20 points) Due Sunday, Nov 29 (really!)

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Drawing a Circle. 78 Chapter 5. geometry.pyde. def setup(): size(600,600) def draw(): ellipse(200,100,20,20) Listing 5-1: Drawing a circle

CS 1301 Exam 1 Fall 2014

Part 1. Summary of For Loops and While Loops

CSC D84 Assignment 2 Game Trees and Mini-Max

Boolean Expressions. Is Equal and Is Not Equal

University of California, Berkeley College of Engineering

append() function, 66 appending, 65, 97, 296 applications (apps; programs), defined, 2, 296

CS 111X - Fall Test 1

Remaining Enhanced Labs

5 R1 The one green in the same place so either of these could be green.

Creating objects TOPIC 3 INTRODUCTION TO PROGRAMMING. Making things to program with.

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

Introduction to Python (All the Basic Stuff)

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2014

CSCE 110: Programming I

nostarch.com/pfk For bulk orders, please contact us at

CS150 Sample Final. Name: Section: A / B

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Structure and Interpretation of Computer Programs

Basics of Programming with Python

CS150 Sample Final Solution

CISC 181 Lab 2 (100 pts) Due: March 7 at midnight (This is a two-week lab)

CS 1110, LAB 1: PYTHON EXPRESSIONS.

Transcription:

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Due: Mar25 (Note that this is a 2-week lab) This lab must be done using paired partners. You should choose a different partner than the partner you worked with previously. One student should turn in the lab, but the lab must have both students names on it. If you want to be really considerate, the other partner should type into the text box in Sakai the name of the partner they worked with, just to be safe. Create a file called lab2.py. Include as comments at the very top of the file: your name, your partner s name, class time, TA s name(s), and lab due date. Then include the following comments and functions: Note: Include the comments in your lab2.py file. This will make the lab easier to read and grade. You should still get into the habit of commenting every function. Comments should include the number and type of the input parameters, the type of the output parameter, and a clear description of exactly what the function does. When possible, the function should include test cases. Comments should be written BEFORE the function is written. Note 2: Test cases for functions that generate random numbers are somewhat difficult. If possible for those cases, give a sample output, i.e., an example of what you might get if a particular random number or set of random numbers are generated. Note that the rest of your comments don t change at all. All functions must have comments. In functions where I have included the comments, copy and paste them into your lab code. Lab Attendance Mar 12: 3 pts Lab Attendance Mar 19: 3 pts 1. (3 pts) Write a function that takes as input parameters 2 strings. It outputs a string. The returned string is the two input strings concatenated together. 2. (3 pts) Write a function that takes as input 2 parameters: a string and an int. It should return 1 longer string the string you input int times. So if your input parameters were ha and 4, the string returned should be hahahaha Problem 3a (3pts). Write the following functions based on the comments, below: # Function name: min2 # Input: 2 integers # Output: an integer # This function returns the smaller of the two input parameters # Test Cases: 3,7->min2->3 # 7,2->min2->2 # 3,3->min2->3 Problem 3b (3 pts). #Function name: min5

#Input: 5 integers #Output: 1 integer # This function should take 5 integers and return the minimum of those 5 integers. This function should be 1 line of code long #Test cases: 12,5,2,6,8 -> min5 -> 2 # 1,2,3,4,5-> min5 ->1 # 5,4,3,2,1->min5->1 3c (2 pts). Run min5 with strings as input parameters instead of integers. Example: # Text Cases: dog, bird, cat, zebra, bear -> min5 -> bear # aardvark, bear, echidna, wombat, zebra ->min5-> aardvark # zebra, wombat, echidna, bear, aardvark ->min5-> aardvark What did you just learn about the less than operator and strings? (Write a small comment answering that right below these test cases). 3d. (2 pts) Run min5 with the following two sets of input parameters: # Text Cases: 50,3800,490,6,20805 -> min5 ->? 50, 3800, 490, 6, 20805 -> min5 ->? Do you get different results? Explain why you got the results you did (Hint: think of the dictionary). While Loops: Random Number Generation Python can generate random numbers. The library dedicated to generating random numbers is called random. So if you want to generate random numbers, you must first import the random number library by placing at the top of your lab2.py file: from random import * The above line should be the top line (under your comments) in your lab2.py file. Now, to generate a random number between 0 and 100 (not including 100) and store it in the variable randvar, you d write the following: randvar = randrange(0,100) Remember, we do the right side first and place the value calculated by the right side into the variable on the left side. So if you use the above code to generate a random number, randrange will generate a number between 0 and 99 (inclusive). Let s say the random number generated is 42. Then randvar will hold the number 42. To see what number is generated, you can always print it: print (randvar) (Note: when writing test cases for functions that use random numbers, you may need to give a range of answers that would be correct. So in this case, I might say: Input: 3->func-> 0 2 (inclusive) Input: 7-> func->0 6 (inclusive) Input: 100->func-> 0 99 (inclusive) NOTE: For those of you who have had programming before, this lab is to ensure sure you understand while loops. You must use while loops as opposed to any other type of loop for these problems. There should be no loops other than while loops in this lab. Problem 9a (2pts): Write a function that takes as an input parameter an integer. Inside the function, it should loop that many times (the value of the input parameter). There should be a total variable, initialized to 0. The loop

should generate a random number between 0 and 10 (not including 10, and add it to the total each time, and, when the loop is done, that total should be returned. Note that in order to check whether the function is working, inside the loop you ll have to print the random number each time. 9b (2 pts) Create a second version of this function that, instead of returning the total, returns the average random number generated. 9c (3 pts) Create a third version of this function that takes a second input parameter that is an integer between 0 and 10. This function counts how many of the random numbers are evenly divisible by the second input parameter and the function returns that count. Problem 10 (3 pts) Write a function that has no input parameters. It asks the user to enter a number between 0 and 100. It also has a count variable. It uses a while loop to generate random numbers. It continues to generate random numbers as long as the random number isn t the same as the number the user entered. It keeps count of the number of random numbers generated. When the random number generated is the same as the user-input number, it stops looping and returns a count of the number of wrong random numbers. Problem 11 (4 pts)in class on the powerpoints, we wrote the following function: def f(): x = int(input("heads or tails? (1 or 0) ")) y = randrange(0,2) if x == y: return("you guessed right! You both guessed " + str(x)) else: print(f()) return("you re wrong. You guessed "+str(x)+" and computer generated "+str(y)) As it is written now, you must call the function each time to make it happen. So, in other words, each time you want to guess Heads or Tails, you ve got to re-run the code. Modify the above code so that: a. Instead of returning You guessed right! You both guessed + str(x)) or You re wrong. You guessed +str(x)+ and the computer generated +str(y)) the function prints those sentences b. The function takes an input parameter, which will be the number of times the while loop loops. c. A loop is placed around the code so that the game is played the input parameter number of times. d. A count variable is added that counts the number of times the user guesses correctly. e. The count is what is returned from the function Problem 12 (5 pts)simple dice game. Sample output: This function (Dice) takes one integer as an input parameter, initialized to 0. It is what will be returned from the function when you re done adding up the values. The output type is also an integer Calculation: This function generates two random numbers between 1 and 6 inclusive. It then calculates your current score as follows: If you roll a 1, your score is set to 0 unless you roll 2 1 s, in which case you add 50 pts to your score. If you roll a 2 add 10 points to your score. If you roll two 3s, you lose 40 points. Otherwise, your score goes up by the addition of the two random numbers. This function will loop either 10 times. It returns the score. (Note: print out the random numbers generated within the function or you won t know whether your function is working or not)

4, 4 5, 1 6, 3 3, 4 3, 6 3, 3 5, 3 4, 2 5, 4 6, 6 24 1, 2 2, 5 2, 2 5, 6 4, 5 1, 5 2, 5 1, 1 1, 3 6, 4 10 1, 6 4, 2 5, 1 2, 2 5, 4 3, 4 3, 2 1, 2 4, 2 4, 5 19 Problem 13 13a. (4 pts) Write a function that takes as input parameters two integers. It returns an integer. It loops. Each time it generates a random number between 1 and the second parameter. If the random number is not equal to the first parameter, the random number is returned. Otherwise, the function loops. (Note: the way to test this function is to put print statements within the function showing the random number generated. You may wish to test this with a very small range in order to make sure that it actually continues to loop when the random number is equal to the first input parameter). So, for instance, I tested this with inputs of 2, and 3. This is the output I got: x is 2, rand num is 2 x is 2, rand num is 1 1 x is 2, rand num is 2 x is 2, rand num is 2

x is 2, rand num is 1 1 x is 2, rand num is 2 x is 2, rand num is 2 x is 2, rand num is 1 1 13b. (2 pts) (Not a loop): Write a function that takes as input parameters 4 integers. It returns a Boolean value. It checks to see if the second two parameters are the same as the first two parameters, regardless of order. In other words: 3,7,3,7 ->checkvalues ->True 7,4,4,7->checkvalues -> True 7,8,7,4->checkvalues -> False 13c. (5 pts) We ve all heard that the lottery is a tax on people who are bad in math. You re going to write a function that tests a simple version of this. For this lottery, you choose only 2 numbers within a range (I think the lottery s range is from 1-40, but I could be wrong on that). The function you are going to write should take 3 input values: the two integers you ve chosen, and the possible range of values (for testing, something smaller than 40, but for the actual lottery it would be 40),. The function should have a loop counter variable, initialized to 0. This is what is returned from the function because it counts how many times it took until you won the lottery. The function will generate 2 different random numbers (to make sure of this, you should use function 13a), then continue to loop until the 2 random numbers are the same as the 2 numbers you chose (your 2 input parameters)(this is checked using function in 13b), counting how many times you re looping using the loop counter. The loop stops when your input parameters and the random numbers are the same, and then the number of times the function had to loop before your input parameters and the random numbers were the same is returned. In other words, it returns how many times you d have to play with those two numbers before you won. Note a. You may always put print statements within your functions to see what they are doing as you run them. Note b: to test your function, you can change the lottery s range to a smaller number than 40. For instance, when I made the range 10 it looped 297 times before I won. When I made t 40, it looped 1427 times before I won. Note c: I m not including output for this one. It s too long. Problem 14: Input function (Versus input parameters) Python s input function is DIFFERENT from input parameters. Input parameters are the values that are passed into a function. The input function is a function that demands that the user type something in. So, for instance, def f(x,y): #x and y are the input parameters, and we put values into x and y outside of the function return(x + y) print(f(3,7) #this is putting values into the parameters. It s where we put 3 into x and 7 into y

Whereas: def f(): x = input( what value, as a number, do you want to enter? ) #Here the string shows up in python s shell #window, and the user must type in a value. #The value will go into x y = input( Enter a second number ) return(x+y) print(f()) #Notice that no values are going in here. In the second function, there are no input parameters. Instead, the function interacts with the user as it runs to get actual values for x and y. 14a. (3 pts) This (nonlooping) function takes 2 integers as input parameters, asks the user what x times y is using the input function for user input, and then returns True if the user inputs the correct value, and false otherwise as follows: #Function name: mult #input parameters: 2 integers #output: a Boolean value #This function checks whether the value the user types in using the input function is equal to the product of the two input parameters and returns True if it is, False otherwise. #Test cases: Input parameter: 3, 7>mult2-> value entered into input function: 21- ->True # Input parameter: 6,4->mult2-> value entered into input function: 18->False # Input parameter: 0-,12>mult2-> value entered into input function: 0->True 14b. (4 pts) Function name: MultTest Input parameters: 2 integers Output: A string This function uses a while loop and the function written in problem 2 (mult) to see how well a student is able to do their multiplication tables. The function checks to see whether a student is able to correctly multiply every number between 2 and 12 with the first input parameter. If the student gets any answer incorrect, the function starts over with 2 times x, then 3 times x, then 4 times x, etc, where x is the first input parameter. Otherwise, the function returns a string saying, Congratulations! You know your x multiplication tables! Test Output (i.e., what you might see): What is 4 times 2? -> 8 What is 4 times 3? -> 12 What is 4 times 4? -> 16 What is 4 times 5? -> 20 What is 4 times 6? -> 24 What is 4 times 7? -> 28 What is 4 times 8? -> 32 What is 4 times 9? -> 36 What is 4 times 10? -> 40 What is 4 times 11? -> 44 What is 4 times 12? -> 48

Problem 15: Contratulations! You know your 4 multiplication tables! What is 6 times 2? -> 12 What is 6 times 3? -> 18 What is 6 times 4? -> 24 What is 6 times 5? -> 30 What is 6 times 6? -> 34 What is 6 times 2? -> 12 What is 6 times 3? -> 18 What is 6 times 4? -> 24 What is 6 times 5? -> 30 What is 6 times 6? -> 36 What is 6 times 7? -> 42 What is 6 times 8? -> 48 What is 6 times 9? -> 54 What is 6 times 10? -> 60 What is 6 times 11? -> 66 What is 6 times 12? -> 72 Contratulations! You know your 6 multiplication tables! 15a.(4 pts) Create a copy of your dice function that stops either when the loop hits 10, or when the user chooses to stop. That means that every time, it should use the user input function to ask the user, Do you wish to continue? If the user says yes, the function continues as before. If no, the current score is returned. Note: this function may take no input parameters, depending on how you write it. Example: 1, 2 4, 1 3, 3 tot so far:-40 5, 4 tot so far:-31 1, 6 6, 3 tot so far:9 1, 4 2, 6 tot so far:10

3, 1 2, 1 0 Example 2: 3, 5 tot so far:8 3, 2 tot so far:18 Do you wish to continue?no 18 15b: (6 pts) Now create a brand new function called dicegame. This function takes 3 integers as its input parameters:, the score of the first player, the score of the second player, and the count of the number of loops. It then loops the count time. Each loop, it calls the first dice function and adds the score to the first player s score, and then it calls the second dice function (above) and the user plays the game. Each time the loop should print out the first player s current score and the second player s current score. When it is done looping, it should say whether the first player or the second player won. Example if the call is dicegame(0,0,2): 1, 3 4, 4 tot so far:8 4, 4 tot so far:16 2, 2 tot so far:26 4, 4 tot so far:34 2, 4 tot so far:44 2, 3 tot so far:54 3, 5 tot so far:62 3, 5 tot so far:70

4, 4 tot so far:78 switching players 1, 6 6, 6 tot so far:12 5, 3 tot so far:20 3, 5 tot so far:28 2, 1 5, 6 tot so far:11 6, 4 tot so far:21 1, 6 2, 5 tot so far:10 2, 4 tot so far:20 score 1:78, score2:20 4, 4 tot so far:86 Do you wish to continue?no switching players 2, 2 tot so far:30 4, 4 tot so far:38 4, 1 5, 4 tot so far:9 2, 2 tot so far:19 5, 4

tot so far:28 4, 5 tot so far:37 6, 5 tot so far:48 4, 6 tot so far:58 4, 2 tot so far:68 score 1:86, score2:68 player 1 won! 86 versus 68 Turtle: Problem T1 ( 3 pts) Function Name: Circles Input: 1 integer: the radius Output: none This function loops until the radius is 0 or less. Each time it draws a circle with the radius, and then loops with a radius 3 smaller than the previous radius. You should get something like this: Problem T2: (4 pts) Function Name: Squares Input: 3 integers: the length of the side, and the starting x and y coordinate Output: none This function loops until the length of the side is 0 or less. Each time it draws a square centered within the previous square, and then loops with a radius 8 smaller than the previous side length. You should get something like this: Note: for this you will need turtle.penup() to lift the turtle pen off the screen, then, of course, turtle.pendown() to put it down on the screen, and you ll need turtle.goto(x,y) which will move the pen to the x y coordinates.

Problem T3: Spirograph/flower To do this problem, you need to know a few things about turtle s color. Color is represented by the amount of red, the amount of green, and the amount of blue (rgb values). Each value is represented by an amount between 0 and 1. To set the color, you use the command: turtle.color(r,g,b) where r is a double between 0 and 1, g is a double between 0 and 1, and b is a double between 0 and 1. You can set turtle s pensize with an int, e.g., turtle.pensize(3) equally, when the pen is at x,y coordinates and a circle is drawn, the x y coordinates default to the very bottom of the circle s circumference, not the center. In order to have the circle drawn with the starting location at the same x/y coordinates but at a different angle, you rotate the direction of the turtle using either turtle.left() or turtle.right(), and the degrees you want to rotate turtle s angle. So for instance, if you wanted to draw 6 circles like a Spirograph, you d rotate turtle.left(60) each time and then draw another circle. Okay, now onto the drawcircles function: T3a (4 pts) drawcircles: This function draws one set of Spirograph circles. It takes 6 (yep, 6!) input parameters: one int representing the count, or number of times the loop still needs to rotate, an int representing the size of the circle, an int representing the amount the turtle should be rotated each time, and then 3 doubles, all between 0 and 1, representing the amount of red, the amount of green, and the amount of blue in the color, respectively. The function should return nothing, using: return It should generate a random number between -.2 and.2 (random number between -20 and 20, divided by 100). And that number should be added to the amount of red. Repeat for green, and for blue. Then check to make sure that the red, green, and blue amounts are within range. If a value is < 0, it should be reset to.1. If it s > 1, it should be reset to.9. The turtle s color should be set to the new red/green/blue values. And a circle should be drawn. Then the loop should continue. So, if the drawcircle is called initially as: Drawcircle(6,25,60,.5,.5,.5) You should get something looking like this:

T3b (7 pts) Spirograph function: This function takes 3 parameters, all three are ints. The first is the count of the number of circle sets you ll create (the drawcircle function creates 1 circle set), and the second and third are the x/y coordinates of where the circles start from. (Note: these don t change throughout, but this function makes sure that we always start from those x/y coordinates in case the pen gets off by a pixel or two). This function loops count times (the first parameter). If it does not stop, it goes to the x/y coordinate. Note: you will want to use the following command: turtle.setheading(0) to reset the direction of the turtle to its original direction You will then randomly choose a number between 4 and 20 for how many circles should be generated for this circle set. Once you know the number of circles, you should calculate how much the rotation should be. Finally, you should randomly generate a number between 20 and 230, which will be the size of each circle. When you have that, you should call your drawcircle function (with initial color values of.5,.5,..5). Then you should loop with the Spirograph function. You might get something that looks like this:

Problem T4(5 pts) In problem 4.2 under the turtle section in the last lab, you wrote a function that took as an input parameter a color, and drew an object. For this problem, you are going to use that function to draw your object all over the turtle window, in different colors. So the function you are now writing, which will loop, should have 1 parameter: the total number of times the loop needs to loop. In the function, you will generate a random number between - 250 and 250 for the x coordinate, and another random number between -250 and 250 for the y coordinate. You should then use turtle.penup() and turtle.goto(x,y) to have the pen go to the new x and y coordinate. Then call the function you wrote in 4.2 (you should copy and paste that function into this lab file, above this function you are writing now). Make sure you generate new random numbers for the color. Problem T5 (10 pts) Rock/Paper/Scissors Copy the following code into Lab 2. Make sure you ve downloaded stone.gif, paper.gif, and Scissors.gif from my web page. Place them in your Python folder on your computer. Then write the following function where indicated.

import turtle import tkinter from random import * tk = tkinter.tk() canvas = tkinter.canvas(tk, width = 500, height = 300, bg="white", bd="5") canvas.pack() def display(you,computer): print("you: " + str(you) + " computer: " + str(computer)) if you == 0: my_img=tkinter.photoimage(file = "stone.gif") elif you == 1: my_img=tkinter.photoimage(file = "paper.gif") elif you == 2: my_img=tkinter.photoimage(file = "Scissors.gif") canvas.create_image(70,60, anchor = tkinter.nw,image = my_img) if computer == 0: c_img=tkinter.photoimage(file = "stone.gif") elif computer == 1: c_img=tkinter.photoimage(file = "paper.gif") elif computer == 2: c_img=tkinter.photoimage(file = "Scissors.gif") canvas.create_image(270,60, anchor = tkinter.nw,image = c_img) tk.update() # function: # Function name: RockPaperScissors # input: 1 integer the number of times the loop should loop # output: a string You won w out of x times, where w is the count of the number of times you won, and x is the number of times the loop looped. # This function should run x times (where x is the input parameter). Each time it should use the input function to ask you, choose 0 for rock,1 for paper, or 2 for scissors:. It should then generate a random number between 0 and 3 (not including 3). It should call the function display() with your choice and the computer s choice. It should then calculate whether you won and, if so, increase the won (w) count. The winner is determined as follows: If the user chose rock: If the computer generated rock, it s a tie If the computer generated paper, the user loses If the computer generated scissors, the user wins If the user chose paper: If the computer generated rock, the user wins If the computer generated paper, it s a tie If the computer generated scissors, the user loses If the user chose scissors: If the computer generated rock, the user loses If the computer generated paper, the user wins If the computer generated scissors, it s a tie Again, this function should loop x times where x is the input parameter

#YOUR FUNCTION GOES HERE! def main(): print(rockpaperscissors(0,0)) main()