Log(5) will fail
log(5)
TypeError: log() missing 1 required positional argument: ‘message’
I created input tests to prevent the error.
def log(sequence, message, *values):
alist = list(values)
for element in alist:
try:
element = int(element)
print('this is not a color, this is a numbers')
print('group', sequence, 'number', element)
print('')
except ValueError:
print('this is a color')
print('group', sequence, message, element)
print('')
pass
def my_generator():
for i in range(10):
yield i
def my_func(*args):
print('')
print('my_generator counts 0 to 10')
print(args)
log(0, 'Favorite colors')
log(1, 'Favorite colors', 7, 33, 16)
log(2, 'Favorite colors', 'red', 'yellow', 'blue')
log(3, 'Favorite colors', 'red', -1, 'blue')
log(4, 'Favorite colors', 'red')
# log(5) will return a Typeerror because it is missing argument message
seq_num = 5
retry = 1
while retry == 1:
message_input = input('what is the message? ')
if message_input == '':
message_input = input('you need to provide the message? ')
values_input = input(' what are the values separated by ,? ')
values_list = values_input.split(",")
for element in values_list:
if not element:
print('you didn\'t give any values')
print('')
else:
try:
element = int(element)
print('this is not a color, this is a number')
print('group', seq_num, 'number', element)
print('')
except ValueError:
print('this is a color')
print('group', seq_num, message_input, element)
print('')
pass
try_again = input('Do you wish to try again? Y or y for Yes or any key for no')
if try_again == 'Y' or try_again == 'y':
seq_num += 1
print('')
else:
retry = 0
print('')
# my generator count 0 to 10 and my_func prints it
it = my_generator()
my_func(*it)
/home/michael/PycharmProjects/Arguments/venv/bin/python /home/michael/PycharmProjects/Arguments/positional.py
this is not a color, this is a number
group 1 number 7
this is not a color, this is a number
group 1 number 33
this is not a color, this is a number
group 1 number 16
this is a color
group 2 Favorite colors red
this is a color
group 2 Favorite colors yellow
this is a color
group 2 Favorite colors blue
this is a color
group 3 Favorite colors red
this is not a color, this is a number
group 3 number -1
this is a color
group 3 Favorite colors blue
this is a color
group 4 Favorite colors red
what is the message?
you need to provide the message? what are the values separated by ,?
you didn't give any values
Do you wish to try again? Y or y for Yes or any key for noy
what is the message? Favorite Color
what are the values separated by ,?
you didn't give any values
Do you wish to try again? Y or y for Yes or any key for noy
what is the message? Favorite Color
what are the values separated by ,? 1,2,3
this is not a color, this is a numbers
group 7 number 1
this is not a color, this is a numbers
group 7 number 2
this is not a color, this is a numbers
group 7 number 3
Do you wish to try again? Y or y for Yes or any key for noy
what is the message? Favorite Color
what are the values separated by ,? red, white, blue
this is a color
group 8 Favorite Color red
this is a color
group 8 Favorite Color white
this is a color
group 8 Favorite Color blue
Do you wish to try again? Y or y for Yes or any key for noy
what is the message? Favorite Color
what are the values separated by ,? 1,2,red,2,3,blue,3,4,green
this is not a color, this is a numbers
group 9 number 1
this is not a color, this is a numbers
group 9 number 2
this is a color
group 9 Favorite Color red
this is not a color, this is a numbers
group 9 number 2
this is not a color, this is a numbers
group 9 number 3
this is a color
group 9 Favorite Color blue
this is not a color, this is a numbers
group 9 number 3
this is not a color, this is a numbers
group 9 number 4
this is a color
group 9 Favorite Color green
Do you wish to try again? Y or y for Yes or any key for no