Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Thank you for trying my little test here. I have never done anything like this before, but I hope
- #That i didn't make these too hard or too easy. This was designed to be for beginner level python
- #students, not someone who's been learning for a very long time. Again, i've never tried to create
- #anything like this, so if I did a terrible job please leave a comment on the facebook post with
- #any feedback/questions/concerns!
- ----------------------------------------------------------------------------------------------------
- # Question 1:
- # the following code is designed to print out a range
- # of numbers (1-20) and print each number followed by "is even" or
- # "is odd" depending on if the number is even or odd. Fix the code.
- # ** BONUS CHALLENGE** if the number is 3 or 14, print "3/14 is unlucky!"
- for numbers in range :
- if numbers :
- print
- elif numbers :
- print
- elif numbers :
- print
- #**HINT** USE F STRINGS FOR CLEANER CODE
- ####################################################################
- # Question 2:
- # The following code is designed to be a random number guessing game.
- # The objective is have the computer generate a random number in a
- # range that the user provides, and you have to guess that number.
- # If the guess is too high, print "Too high!" or if it's too low,
- # print "Too low!" If the guess is correct, print "Winner winner chicken dinner!"
- # **BONUS CHALLENGE** add a loop to ask the player if they'd like to play again
- rng =
- answer = randint(0, rng)
- guess = int(input(f"Guess a number between 0 and {rng}"))
- ##If your guess is too high
- while guess
- if guess answer:
- "Your guess of {guess} was too high, try again! "
- ##If your guess is too low
- elif guess answer:
- guess = int(input(f"Your guess of {guess} was too low, try again! "))
- ##If you're correct
- if guess = answer:
- input("Great job!")
- #Ask to play again
- again "Would you like to play again?"
- #if yes to play again
- if again
- #If no to play again
- elif again
- print("Thanks for playing!")
- #**HINT** how do you have the computer randomly select a number?
- ###################################################################
- # Question 3:
- # The following code is designed to mimic a bouncer at a bar. It will ask
- # you for your age, and determine whether you're allowed in the bar or if you
- # can drink. If you're under 18, you can't go in. If you're 18-20 you can go in
- # but no drink alcohol, if you're 21+ you can go in and drink.
- age = input("How old are you?")
- if age:
- # ages 18-21 wear wristbands
- if age
- print("You can enter with a wristband.")
- #21+ drink, normal entry
- elif age
- print("You can enter and drink")
- #<18 too young
- print("You cannot come in, young person.")
- else:
- print("You didn't enter an age.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement