I am writing code to have the user enter the number of bottles of beer on the while and the output should be the verses of the song down to 1. I am trying to get the proper number of unicode mugs of beer to print before the verse (5 mugs, then sing 5 bottles of beer, 4 mugs, then 4 bottles of beer, etc). I have 3 issues:
- am getting an equal number of grey diamonds with question marks
- if I sing the song again, the top number of beer mugs doesn't print, I just get the correct number of grey diamonds and
- (but I can't always reproduce this), I have the song sing differently if you enter an age under 21 and it prints cups with straws (for root beer).
If you switch age groups, it sometimes prints a mix of beer mugs and cups of straws. It does it with no discernible pattern.
Code is as follows:
def sing(num):
print( "\n" +str(num) +" Bottles of beer on the wall. \n"+ str(num) +" Bottles of beer. \nTake one down, pass it around. \n" +str(num-1) +" Bottles of Beer on the wall. \n \n")
# print("\N{beer mug}")
def lastbottle():
print("1 Bottle of beer on the wall.\n1 Bottle of beer.\nTake one down, pass it around. \nNo more bottles of beer on the wall! \nGo to the store and buy some more! 99 bottles of beer on the wall!\n")
def singUnderAge(num):
print( "\n" + str(num) +" Bottles of root beer on the wall. \n"+ str(num) +" Bottles of root beer. \nTake one down, pass it around. \n" +str(num-1) +" Bottles of root beer on the wall. \n \n")
#print("\N{cup with straw}")
def lastbottleUnderAge():
print("1 Bottle of root beer on the wall.\n1 Bottle of root beer.\nTake one down, pass it around. \nNo more bottles of root beer on the wall! \n\nYou've had enough sugar for one day. \nNow brush your teeth and go to bed!\n")
#print("\N{bed}")
def valid_num():
isValid = False
while not isValid:
try:
num = int(input("How many bottles should we begin with? (1-99) "))
if num > 0 and num < 100:
isValid = True
except:
("Please enter a number between 1 and 99: ")
return(num)
def valid_age():
#isValid = True
while True:
try:
age = float(input("How old are you? "))
#if age > 0 and age < 120:
#isValid = True
except ValueError:
("Please enter a number for your age: ")
continue
else:
return(age)
break
def ageCheck(num):
if age >= 21:
num = valid_num()
for i in range(num, 1,-1):
for count in range(0,i):
print("", end="", flush=True)
sing(i)
else:
print("", flush=True)
lastbottle()
else:
print("You are not old enough to drink beer. Here is a more appropriate version.\n")
num = valid_num()
for i in range(num, 1,-1):
for count in range(0,i):
print('', end="", flush=True)
singUnderAge(i)
else:
print("\N{cup with straw}", flush=True)
lastbottleUnderAge()
singSong = True
while singSong:
age = valid_age()
ageCheck(age)
singSong = input("Would you like to perform another song? ")
no_list = ["No","N","n","Nyet","Nein","Non","no","NO"]
if (singSong in no_list):
singSong = False
print("Thank you. Have a nice day!")