Whenever I run the display_data function (when there is data to be run after successfully answering at least one calculation_game question) I get an error that says:
"ValueError: to_rgba: Invalid rgba arg "o"
to_rgb: Invalid rgb arg "o"
could not convert string to float: 'o'"
When I run the code without the "o" to define the shape of the points it works fine and displays blue points. Only thing is that I want to be able to define shapes such as "o" and "v" because the plot will be showing data from multiple list when it is done. Any ideas?
NOTE:
There are missing functions below. I removed them here because they are not needed for the question.
import random
from random import randint
import time
import math
import matplotlib.pyplot as plt
# Number of problems for each practice/real round
practice_round = 0
real_round = 3
main_record = []
CALC_RECORD = []
# (1) Calculation Game ---------------------------------------------------------
'''Calculation game is a math game'''
def calculation():
response_time = None
# Determine the min and max calculation values
min_calculation_value = 1
max_calculation_value = 10
# Generate the problems
print('\nSolve the following problem:')
a = random.randint(min_calculation_value, max_calculation_value)
b = random.randint(min_calculation_value, max_calculation_value)
problem_type = random.randint(1,2)
if problem_type == 1:
answer = a * b
print(a, '*', b)
elif problem_type == 2:
answer = a % b
print(a, '%', b)
# Get the user's answer determine what to do if correct
start_time = time.time()
user_answer = input('\nEnter your answer: ')
end_time = time.time()
if user_answer == str(answer):
response_time = end_time - start_time
print('You are correct!')
elif user_answer != str(answer):
print('Oops, you are incorrect.')
# Return game id, start time, and response time
return("calculation", start_time, response_time)
def calculation_game():
record = []
# Generate two problems for a practice round
print("\nLet's begin with 2 practice problems.")
for i in range (practice_round):
print('\nPractice Problem', i + 1, 'of', practice_round)
calculation()
# Generate 10 problems for a real, recorded round
print("\nNow let's try it for real this time.")
for i in range (real_round):
print('\nProblem', i + 1, 'of', real_round)
# Append records for each iteration
record.append(calculation())
main_record.extend(record)
CALC_RECORD.extend(record)
return record
# (5) Display Data -------------------------------------------------------------
def display_data():
plt.ylabel('Time Per Question')
plt.xlabel('Round Played')
CALC_RECORD.sort(key=lambda record:record[1])
calc_time = [t[2] for t in CALC_RECORD if t[0] =='calculation' and t[2] != None]
alist=[i for i in range (len(calc_time))]
if len(calc_time) >0:
print (calc_time)
x = alist
y = calc_time
plt.scatter(x, y, c="bo")
plt.show(block=True)
main_menu()
# (6) Save Progress ------------------------------------------------------------
# (7) Load Data ----------------------------------------------------------------
# (8) Quit Game ----------------------------------------------------------------
def quit_game():
print('\nThank you for playing!')
# Main Menu --------------------------------------------------------------------
def menu():
print("\nEnter 1 to play 'Calculation'")
print("Enter 2 to play 'Binary Reader'")
print("Enter 3 to play 'Trifacto'")
print("Enter 4 to view your statistics")
print("Enter 5 to display data")
print("Enter 6 to save your progress")
print("Enter 7 to load data")
print("Enter 8 to quit the game")
def main_menu():
print('Welcome!')
user_input = ''
while user_input != '8':
menu()
user_input = input('\nWhat would you like to do? ')
if user_input == '1':
calculation_game()
if user_input == '2':
binary_reader_game()
if user_input == '3':
trifacto_game()
if user_input == '4':
display_statistics()
if user_input == '5':
display_data()
if user_input == '8':
quit_game()
main_menu()
Got it, just had to remove the c= part from plt.scatter(x, y, c="bo")
Related
how would I solve this problem? The program is supposed to remove all pairs from your hand at the beginning but it is not working. This is what it outputs at the moment:
Hello. I am Robot and I distribute the cards.
Your hand is:
2♠ 5♡ Q♠ Q♡ 4♡ J♢ 2♣ J♠ K♢ 8♢ 10♠ A♣ 5♣ 3♣ 6♣ 4♢ 7♣ 9♢ 2♢ J♡ A♢ 8♠ 10♣ 6♢ 10♡
Don't worry, I cannot see your cards or their order.
Now discard all pairs in your hand. I will do it too.
Press Enter to continue.
************************************************************
Your turn.
Your hand is:
9♢ J♡ 3♣ K♢ 10♠ 2♢ 10♣ 10♡ 7♣
There is not supposed to be two 10s in your hand. This is the code:
# vieux garcon card game.
import random
def wait_for_player():
try:
input("Press Enter to continue. ")
except SyntaxError:
pass
def prepare_pack():
pack = []
colors = ['♠', '♡', '♢', '♣']
value = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
for val in value:
for color in colors:
pack.append(val + color)
pack.remove('J♣')
return pack
def shuffle_pack(p):
random.shuffle(p)
def give_cards(p):
giver = []
other = []
loop = 0
for i in p:
if (loop % 2) == 0:
giver.append(i)
else:
other.append(i)
loop += 1
return (giver, other)
def remove_pairs(l):
colors = ['♠', '♡', '♢', '♣']
result = []
for crt in l:
if crt[1] + crt[0] == '10':
nbr = '10'
else:
nbr = crt[0]
for i in colors:
find = False
if nbr + i in result:
find = True
result.remove(nbr + i)
break
if find == False:
result.append(crt)
random.shuffle(result)
return result
def show_cards(p):
for i in p:
print(i, end = " ")
print()
def enter_valid_position(n):
enter = int(input('Please enter a number from 1 to'+ str(n) +": ")) - 1
while enter not in range(0, n):
enter = int(input('Invalid position. Please enter a number from 1 to ' + str(n) +": ")) - 1
return enter
def play():
p = prepare_pack()
shuffle_pack(p)
tmp = give_cards(p)
giver = tmp[0]
human = tmp[1]
print("Hello. I am Robot and I distribute the cards.")
print("Your hand is:")
show_cards(human)
print("Don't worry, I cannot see your cards or their order.")
print(
"Now discard all pairs in your hand. I will do it too."
)
wait_for_player()
giver = remove_pairs(giver)
human = remove_pairs(human)
#Instance = 1, human's turn, instance = 2, robot's turn
instance = 1
while instance in range(1,2):
if instance == 1:
print('*' * 60)
print('Your turn.')
print('Your hand is: ')
show_cards(human)
print("I have ", len(giver), "cards. If 1 is the position of my first card and ")
print(len(giver), "is the position of my last card, which card do you want?")
entry = enter_valid_position(len(giver))
print("You asked for my card number ", entry+1, ".")
print("There it is. It is a ", giver[entry])
print("With ", giver[entry]," added, your hand is:")
human.append(giver[entry])
giver.remove(giver[entry])
show_cards(human)
human=remove_pairs(human)
if len(human) == 0:
print("I finished all the cards.")
win = True
break
print("After discarding all pairs and shuffling the cards, your hand is:")
show_cards(human)
wait_for_player()
instance = 2
pass
if instance == 2:
print('*' * 60)
print('My turn.')
take_card = random.randint(0, len(human) - 1)
giver.append(human[take_card])
human.remove(human[take_card])
print("I took your card number ", take_card+1,".")
giver=remove_pairs(giver)
if len(giver)==0:
print("I finished all the cards.")
win = False
break
wait_for_player()
instance = 1
pass
if win == True:
print("Congratulations! You, Human, have won.")
else:
print("You lost! Me, Robot, have won.")
# main
play()
What should I do? My program does remove pairs later on in the game, but not at the beginning.
I found my error.
for crt in l:
if crt[1] + crt[0] == '10':
nbr = '10'
I flipped the positions of the 1 and 0. it was checking for 01 and not 10. It was supposed to be:
for crt in l:
if crt[0] + crt[1] == '10':
nbr = '10'
Sorry for the inconvience.
I'm creating a program so that a track coach can easily pull up runners times as well as input them.
I'm trying to figure out why when I start my program, it runs the function 'MENU', looping it.
user_input = 0
print('MENU')
print('1 - Add runner data to file')
print('2 - Display runners and their times')
print('3 - Calculate the average run time')
print('4 - Display the fastest time')
print('5 - EXIT')
print()
def MENU():
user_input = int(input('Enter your Menu choice >> '))
return -1
def DATA(f_runner, f_time):
f_runner = str(input('Enter runners name >> '))
f_time = str(input('Enter the runners time in hours >> '))
print('Runners data entered into the file.')
f = open('myFile.txt', 'w')
f.write(str(f_runner))
f.write(str(f_time))
f.close()
return f_runner, f_time
def DISPLAY():
contents = f.readlines()
f = open('myFile.txt')
print(contents)
runners_data = 0
runner = 0
runner_time = 0
average_time = 0
file_runner = ''
file_time = 0.0
contents = ''
program_exit = False
menu_start = 0
while program_exit == False:
menu_start = MENU()
while user_input > 0 and user_input < 6:
if user_input == '1':
DATA(file_runner, file_time)
elif user_input == '2':
Display()
elif user_input == '5':
program_exit = True
You are returning -1 instead of user_input in MENU()
Alongside what Samraj said, I believe it's also because your if statement is comparing if the user input is returned as a string, when you're expecting the user to return an int.
You could just remove it from the bottom and have it run inside menu and just call MENU().
Try this and edit it to what you need
print('MENU')
print('1 - Add runner data to file')
print('2 - Display runners and their times')
print('3 - Calculate the average run time')
print('4 - Display the fastest time')
print('5 - EXIT')
print()
def MENU():
the_input = int(input('Enter your Menu choice >> '))
if the_input == 1:
print("hello")
DATA(file_runner, file_time)
elif the_input == 2:
Display()
elif the_input == 5:
exit()
return the_input
def DATA(f_runner, f_time):
f_runner = str(input('Enter runners name >> '))
f_time = str(input('Enter the runners time in hours >> '))
print('Runners data entered into the file.')
f = open('myFile.txt', 'w')
f.write(str(f_runner))
f.write(str(f_time))
f.close()
return f_runner, f_time
def DISPLAY():
contents = f.readlines()
f = open('myFile.txt')
print(contents)
runners_data = 0
runner = 0
runner_time = 0
average_time = 0
file_runner = ''
file_time = 0.0
contents = ''
program_exit = False
menu_start = 0
MENU()
While programming in Python I got stuck in a case where the while loop is not terminating even after the condition is being satisified then also
the code is as follows:
print('--- Alex\'s Calculator ---')
print('1. ADDition')
print('2. SUBstraction')
print('3. MULtiply')
print('4. DIVide')
print('5. EXIT')
x = int(input())
command = ' Enter Your Two numbers To Perform The Operation : '
def ini():
a = int(input())
b = int(input())
return a, b
def resultoo():
result = ' Your Result after Performing The Operation from {} and {} is {}'
print(result.format(a,b,c))
print(' Want To Continue If Yes then Enter Your Choice else Press any number exept 1 - 4')
x = int(input())
while x < 5:
if x == 1:
print(command)
a, b = ini()
c = a + b
resultoo()
elif x < 5:
break
As kuro specified in the comment, x can't be seen by your while loop because it's local to resultoo().
To solve it easily just add :
return x
at the end of resultoo()
and
x = resultoo()
in your while loop
You can use global var to this, change the this:
def resultoo():
result = ' Your Result after Performing The Operation from {} and {} is {}'
print(result.format(a,b,c))
print(' Want To Continue If Yes then Enter Your Choice else Press any number exept 1 - 4')
x = int(input())
into:
def resultoo():
global x
result = ' Your Result after Performing The Operation from {} and {} is {}'
print(result.format(a,b,c))
print(' Want To Continue If Yes then Enter Your Choice else Press any number exept 1 - 4')
x = int(input())
Explnation:
x is a global argument, that will be the same out of the function closure, but not inside of it, the function has it own params, so if you want to change a global argument that is initalizing outside the function, you will need to call the global statement before, that will make x the global x
When option 5 is entered you want to exit.
I added
import sys
and changed
elif x < 5:
to
elif x == 5:
and added
sys.exit(0)
I also added the getMenu() function
This is the complete code that is working in my editor:
import sys
def ini():
command = ' Enter Your Two numbers To Perform The Operation : '
print(command)
a = int(input())
b = int(input())
return a, b
def resultoo(a, b, c):
result = ' Your Result after Performing The Operation from {} and {} is {}'
print(result.format(a, b, c))
def getMenu(x):
if x == 0:
print("Choose menu item")
x = int(input())
elif x != 0:
print(' Want To Continue If Yes then Enter Your Choice else Press any number exept 1 - 4')
x = int(input())
return x
def main():
x = 0
while x < 5:
print('\n\n1. ADDition')
print('2. SUBstraction')
print('3. MULtiply')
print('4. DIVide')
print('5. EXIT\n')
x = getMenu(x)
if x == 1:
a, b = ini()
c = a + b
resultoo(a, b, c)
elif x == 5:
sys.exit(0)
else:
print("No valid menu item")
if __name__ == '__main__':
print('----------------------------------------------------------------------------------------------------------')
print('-------------------------------------------- Alex\'s Calculator -------------------------------------------')
main()
I also formatted your code (alt+Enter in Pycharm) to comply to PEP8 standards ;)
I am new to coding and has recently started learning python. My first challenge is to build a tic tac toe game. Below are my codes for the game, everything worked fine except that when there is no winner(i.e. game draw); i want to display no body has won the game. I've tried to incorporate an else in various places. but, they didn't help. Here is my code.
# a dictionary to display the grid
grid = {
'1':'1', '2':'2', '3':'3',
'4':'4', '5':'5', '6':'6',
'7':'7', '8':'8', '9':'9'
}
# a list to store the values that has already been entered
used_places = []
# players and their symbols
player_1 = 'x'
player_2 = 'o'
# to store result
result = None
def grid_display():
#this function displays the grid
print('\n\n')
print(grid['1'], '\t|\t', grid['2'], '\t|\t', grid['3'])
print(''.rjust(19,'*'))
print(grid['4'], '\t|\t', grid['5'], '\t|\t', grid['6'])
print(''.rjust(19, '*'))
print(grid['7'], '\t|\t', grid['8'], '\t|\t', grid['9'])
def win_the_game():
# this function checks for result and returns true or false
if(
(grid['1'] == grid['2'] == grid['3']) or (grid['4'] == grid['5'] == grid['6']) or
(grid['7'] == grid['8'] == grid['9']) or (grid['1'] == grid['4'] == grid['7']) or
(grid['2'] == grid['5'] == grid['8']) or (grid['3'] == grid['6'] == grid['9']) or
(grid['1'] == grid['5'] == grid['9']) or (grid['3'] == grid['5'] == grid['7'])
):
return True
else:
return False
def taking_turns(turn):
#this function asks user for input
print("its turn of ", turn)
choice = input("enter your choice")
while not (choice.isdecimal() and choice in grid and (choice not in used_places)):
# taking proper input by checkin it with already entered numbers
# and if it is a number
# and if number is in between 1 and 9
choice = input("\nenter your choice properly:")
player_move(choice, turn)
def player_move(move, assign):
# this function fills the entered numbers into used_places list
# and replaces numbers in grid with user input
used_places.append(move)
grid[move] = assign
print("player 1 : 'X'")
print("player 2 : 'O'")
for i in range(0,10): # loops 9 times to play the game
if i % 2 == 0: # giving turns. if i is even, player 1 gets turn and odd, player 2
grid_display() # displaying complete grid
turn = player_1 # to display whose turn it is; refer the function
taking_turns(turn)
if win_the_game() == True: # if the called function returns true in this 'if'
result = turn # player 1 wins
break
else:
grid_display() # same code as above
turn = player_2
taking_turns(turn)
if win_the_game() == True:
result = turn
break
print('\n\n',result, "won the game!!") # printing result
Instead of setting result = None, set result = 'Nobody'.
Looking at your logic, you only set result if somebody wins, this would leave the default of result to nobody.
-- edit --
Sorry, I kinda got carried away and re-wrote the logic of your game in proving my solution. Take it or leave it, but it works great now and maybe you can use it as an example to fix your own.
import os
# a dictionary to display the grid
grid = {
'1':'1', '2':'2', '3':'3',
'4':'4', '5':'5', '6':'6',
'7':'7', '8':'8', '9':'9'
}
# a list to store the values that are available
places = ['1','2','3','4','5','6','7','8','9']
# to store result
result = 'Nobody'
# starting player
turn = 'O'
# display a game grid
def grid_display():
os.system('cls' if os.name == 'nt' else 'clear')
#this function displays the grid
print
print(grid['1'], '|', grid['2'], '|', grid['3'])
print(''.rjust(25,'*'))
print(grid['4'], '|', grid['5'], '|', grid['6'])
print(''.rjust(25, '*'))
print(grid['7'], '|', grid['8'], '|', grid['9'])
# check to see if anyone has won or are we out of moves
def win_the_game():
# this function checks for result and returns true or false
if(
(grid['1'] == grid['2'] == grid['3']) or (grid['4'] == grid['5'] == grid['6']) or
(grid['7'] == grid['8'] == grid['9']) or (grid['1'] == grid['4'] == grid['7']) or
(grid['2'] == grid['5'] == grid['8']) or (grid['3'] == grid['6'] == grid['9']) or
(grid['1'] == grid['5'] == grid['9']) or (grid['3'] == grid['5'] == grid['7'])
):
return True
# checks if there are any moves left
elif not places:
return False
else:
return False
# input / grid update function
def taking_turns():
# this function asks user for input
# use RAW_INPUT to make it a string
print
print map(str, places)
choice = raw_input("\nEnter "+turn+"'s choice: ")
if choice in places:
# this removes the number from the available list
# and replaces numbers in grid with user input
places.remove(choice)
grid[choice] = turn
# Logic loop
while places:
grid_display() # always display the grid
if turn == "O": # giving turns.
turn = 'X'
taking_turns()
if win_the_game() == True: # if the called function returns true in this 'if'
result = turn # player 1 wins
grid_display() # Winners GRID
break
else:
turn = 'O'
taking_turns()
if win_the_game() == True:
result = turn
grid_display() # Winners GRID
break
# results
print
print(result, "won the game!!") # printing result
print
I'm attempting to create a menu-driven program where python will accept a collection of non-negative integers. It will calculate the mean and median and display the values on the screen. I want my first option to be "Add a number to the list/array", I want my second option to be "Display the mean", the third to be "Display the median", the fourth "Print the list/array to the screen", the fifth "Print the list/array in reverse order" and the last option "Quit". So far I have gotten:
def main():
myList = [ ]
addOne(myList)
choice = displayMenu()
while choice != '6':
if choice == '1':
addOne(myList)
elif choice == '2':
mean(myList)
elif choice == '3':
median(myList)
elif choice == '4':
print(myList)
elif choice == '5':
print(myList)
choice = displayMenu()
print ("\nThanks for playing!\n\n")
def displayMenu():
myChoice = '0'
while myChoice != '1' and myChoice != '2' \
and myChoice != '3' \
and myChoice != '4' and myChoice != '5':
print("""\n\nPlease choose
1. Add a number to the list/array
2. Display the mean
3. Display the median
4. Print the list/array to the screen
5. Print the list/array in reverse order
6. Quit
""")
myChoice = input("Enter option---> ")
if myChoice != '1' and myChoice != '2' and \
myChoice != '3' and myChoice != '4' and myChoice != '5':
print("Invalid option. Please select again.")
return myChoice
#This should make sure that the user puts in a correct input
def getNum():
num = -1
while num < 0:
num = int(input("\n\nEnter a non-negative integer: "))
if num < 0:
print("Invalid value. Please re-enter.")
return num
#This is to take care of number one on the list: Add number
def addOne(myList):
while True:
try:
num = (int(input("Give me a number:")))
num = int(num)
if num < 0:
raise exception
print("Thank you!")
break
except:
print("Invalid. Try again...")
myList.append(num)
#This should take care of the second on the list: Mean
def mean(myList):
myList = [ ]
listSum = sum(myList)
listLength = len(myList)
listMean = listSum / listLength
print("The mean is", listMean)
#This will take care of number three on the list: Median
def median(myList):
median = 0
sortedlist = sorted(myList)
lengthofthelist = len(sortedlist)
centerofthelist = lengthofthelist / 2
if len(sortedlist) % 2 ==0:
return sum(num[center - 1:center + 1]) / 2.0
else:
return num[center]
print("The mean is", centerofthelist)
#This will take care of the fourth thing on the list: Print the list (In order)
def sort(myList):
theList.sort(mylist)
print(myList)
#This will take care of the fifth thing on the list
def reversesort(myList):
theList.sort(reverse=True)
print(myList)
main()
After I run the program I can't get past creating the list.
Corrected code with minimum changes:
def main():
myList = []
choice = 1
while choice != 6:
if choice == 1:
option1(myList)
elif choice == 2:
option2(myList)
elif choice == 3:
option3(myList)
elif choice == 4:
option4(myList)
elif choice == 5:
option5(myList)
choice = displayMenu()
print ("\nThanks for playing!\n\n")
def displayMenu():
myChoice = 0
while myChoice not in [1, 2, 3, 4, 5]:
print("""\n\nPlease choose
1. Add a number to the list/array
2. Display the mean
3. Display the median
4. Print the list/array
5. Print the list/array in reverse order
6. Quit
""")
myChoice = int(input("Enter option---> "))
if myChoice not in [1, 2, 3, 4, 5]:
print("Invalid option. Please select again.")
return myChoice
# Option 1: Add a number to the list/array
def option1(myList):
num = -1
while num < 0:
num = int(input("\n\nEnter a non-negative integer: "))
if num < 0:
print("Invalid value. Please re-enter.")
myList.append(num)
# Option 2: Display the mean
def option2(myList):
print("The mean is ", sum(myList) / len(myList))
# Option 3: Display the median
def option3(myList):
sortedlist = sorted(myList)
if len(sortedlist) % 2:
median = myList[int(len(sortedlist) / 2)]
else:
center = int(len(sortedlist) / 2)
median = sum(myList[center-1:center+1]) / 2
print("The median is", median)
# Option 4: Print the list/array
def option4(myList):
print(sorted(myList))
# Option 5: Print the list/array in reverse order
def option5(myList):
print(sorted(myList, reverse=True))
main()
How I would do this:
The first part of the following code are a set of constants to customize the style of the menu. Then a set of functions representing each option are defined. The following 3 functions should not be modified, they generate the menu, display it and close the application. Then the main section starts, where you need to pass every option as an argument to setOptions(). The rest should not be modified either as it is the main loop.
# Menu formatting constants
MENU_HEADER = "Please choose an option:"
MENU_FORMAT = " * {:2}. {}"
MENU_QUIT_S = "Quit"
MENU_ASK_IN = "Enter option: "
MENU_INT_ER = "ERROR: Invalid integer. Please select again."
MENU_OPT_ER = "ERROR: Invalid option. Please select again."
END_MESSAGE = "Thanks for playing!"
# OPTIONS FUNCTIONS START HERE
def addElement(l):
""" Add a number to the list/array. """
n = -1
while n < 0:
try:
n = int(input("Enter a non-negative integer: "))
except ValueError:
print("It needs to be an integer.")
n = -1
else:
if n < 0:
print("It needs to be a non-negative integer.")
l.append(n)
def mean(l):
""" Calculate the mean. """
print("Mean: {:7.2}".format(sum(l) / len(l)))
def median(l):
""" Calculate the median. """
l = sorted(l)
p = int(len(l) / 2)
print("Median: {:7.2}".format(l[p] if len(l)%2 else sum(l[p-1:p+1])/2))
def oprint(l):
""" Print the list/array. """
print(sorted(l))
def rprint(l):
""" Print the list/array in reverse order. """
print(sorted(l, reverse=True))
# OPTIONS FUNCTIONS END HERE
def onQuit(l):
""" Function to execute when quitting the application. """
global quit
quit = True
print(END_MESSAGE)
def setOptions(*args):
""" Generates the menu and the options list. """
# Menu header and quit option (option 0)
menu = [MENU_HEADER]
options = [onQuit]
# Passed arguments represent texts and functions of additional options
for i, f in enumerate(args, start=1):
menu.append(MENU_FORMAT.format(i, f.__doc__.strip()))
options.append(f)
# We print the option 0 the last one
menu.append(MENU_FORMAT.format(0, MENU_QUIT_S))
# Returning both the menu and the options lists
return tuple(menu), tuple(options)
def displayMenu(menu):
""" Display the menu and get an option that is an int. """
while True:
for line in menu:
print(line)
try:
choice = int(input(MENU_ASK_IN))
except ValueError:
print(MENU_INT_ER)
else:
return choice
if __name__ == '__main__':
# Pass the option functions to the setOptions function as arguments
menu, options = setOptions(
addElement,
mean,
median,
oprint,
rprint
)
# Initiate the needed variables and start the loop
l = []
quit = False
while not quit:
c = displayMenu(menu)
try:
f = options[c]
except IndexError:
print(MENU_OPT_ER)
else:
f(l)
There is an indentation error inside your function addOne.
myList.append(num) is inside the while loop, and just before that you have a break, so the number is never appended to the list because we have left the loop already.