I'm having some trouble figuring this problem out.
I have a function that has random.randint(alpha_low,alpha_high)
. alpha_low
and alpha_high
are letters that got turned into numbers values using the function ord
. I then turn them back by using the function chr
so that I get a random letter, and append it to final_list.
The problem is that I want half of the list in caps, and half in lowercase. But right now, for some reason, my code is not printing half half, although I specified that I want half of it to remain the same, and half to be .upper()
.
import random
def alpha_list(num_values, alpha_low, alpha_high):
final_list = []
for letter in range(num_values):
rando = (chr(random.randint(alpha_low, alpha_high)))
final_list.append(rando)
for i in range(len(final_list)):
if final_list[i] > final_list[int((len(final_list)/2)-1)]:
final_list[i] = final_list[i].upper()
else:
pass
return final_list
user_input_number = eval(input('please type an EVEN amount of letters you want: '))
user_input_first_letter = ord(input('please type the first letter of the limits(lower case): '))
user_input_last_letter = ord(input('please type the last letter of the limits(lower case): '))
print(alpha_list(user_input_number, user_input_first_letter, user_input_last_letter))
I have tried to split the list into 2 lists, and uppercase that list, then combine the lists again, but I feel like that isn't the best way.