IT/Python: Codecademy
8 Loop
Last72
2018. 2. 28. 21:26
count = 0 while count < 10: # Add a colon print count count += 1 # Increment count // count = 0 while True: print count count += 1 if count >= 10: break // from random import randint # Generates a number from 1 through 10 inclusive random_number = randint(1, 10) guesses_left = 3 # Start your game! while guesses_left > 0: guess = int(raw_input("Your guess: ")) if guess == random_number: print "You win!" break guesses_left -= 1 else: print "You lose!" // hobbies = [] # Add your code below! for a in range(3): i = raw_input('Select a hobbie') hobbies.append(i) print hobbies // choices = ['pizza', 'pasta', 'salad', 'nachos'] print 'Your choices are:' for index, item in enumerate(choices): print index + 1, item // list_a = [3, 9, 17, 15, 19] list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90] for a, b in zip(list_a, list_b): # Add your code here! print max(a, b) // fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape'] print 'You have...' for f in fruits: if f == 'tomato': print 'A tomato is not a fruit!' # (It actually is.) break print 'A', f else: print 'A fine selection of fruits!'
And, bunch of excercises. answers are below.
https://github.com/ummahusla/Codecademy-Exercise-Answers/tree/master/Language%20Skills/Python