import random #Question 1, print name out 10 times for i in range(10): print('Ricky') #Question 2, print red and gold 20 times for i in range(20): print('Red') print('Gold') #Question 3, print even numbers from 2 to 100 for i in range(2,102,2): print i #Question 4, countdown with while loop clock = 10 while clock > 0: print clock clock = clock - 1 if clock == 0: print('Blast off!') #Question 5, 3 things that are wrong print("This program takes three numbers and returns the sum.") total = 0 for i in range(3): x = input("Enter a number: ") total = total + i print("The total is:", x) #Issues, the x value would only be for the last number inputted, 'total' has no use, the equation should be x1 + x2 +x3 = x #Question 6, random number between 1 and 10 x = random.randrange(10) print x #Question 7, generate random number my_number = random.random() *1 + 10 print my_number #Question 8 total_value = 0 positive_numbers = 0 negative_numbers = 0 equal_to_zero = 0 numb1 = input('enter a number ') numb2 = input('enter a number ') numb3 = input('enter a number ') numb4 = input('enter a number ') numb5 = input('enter a number ') numb6 = input('enter a number ') numb7 = input('enter a number ') total_value = numb1 + numb2 + numb3 + numb4 + numb5 + numb6 + numb7 print total_value if numb1 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb2 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb3 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb4 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb5 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb6 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 if numb7 > 0: positive_numbers = positive_numbers + 1 elif numb1 < 0: negative_numbers = negative_numbers + 1 else: equal_to_zero = equal_to_zero + 1 print equal_to_zero print positive_numbers print negative_numbers #Question 9, random coin flips random_number = random.randrange(0,1) print random_number if random_number == 0: print('Heads') else: print('Tails') aaa = 0 for i in range(50): random_number = random.randrange(0,1) print random_number if random_number == 0: print('Heads') aaa = aaa +1 else: print('Tails') print('Number of heads', aaa) aaa = 50 - aaa print('Number of tails',aaa) #Question 10 y_rps = input('Rock "1" Paper "2" Scissors "3"') rps = random.randrange(1,3) if rps == 1 and y_rps == 2: print('You win') elif rps == 2 and y_rps == 3: print('You win') elif rps == 3 and y_rps == 1: print('You win') else: print('You Lose')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question