while-loop

Wanted to make it shorter and "while" is not working now

Wanted to make it shorter and "while" is not working now Question: I had this code: num1, check = None, None proceed_answer = input(‘Great, we have one more game, wanna play? (y/n): ‘) if proceed_answer == ‘y’: while True: if num1 is None or not check_valid_number(num1): try: num1 = float(input(‘Enter one valid number: ‘)) except …

Total answers: 1

Printing "count" of even numbers while-loop with if

Printing "count" of even numbers while-loop with if Question: I am suppose to be able to complete the following in Python… Fill in the blanks to complete the function “even_numbers(n)”. This function should count how many even numbers exist in a sequence from 0 to the given “n” number, where 0 counts as an even …

Total answers: 5

Parallel while loop with unknown number of calls

Parallel while loop with unknown number of calls Question: I have written a function that does some calculations, and that everytime it is called it returns a different result, since it uses a different seed for the random number generator. In general, I want to run this functions many times, in order to obtain many …

Total answers: 1

While loop not executing passed the user input

While loop not executing passed the user input Question: #imports a library to call on random integers import random user_choice = ” random_num1 = 0 random_num2 = 0 random_num3 = 0 #keeps the loop going until ended by the user while user_choice != "n": user_choice = input(f’Welcome to the slot machine, would you like to …

Total answers: 1

How to set ships randomly using pygame

How to set ships randomly using pygame Question: I want to set ships like in image using pygame. However I got coordinates only from #right(in long for loop). How can I fix this? for i in range(1,6): while True: x,y = random.randrange(14,24,1),random.randrange(1,11,1) angle = ship_angle[random.randrange(0,4,1)] X,Y = x+i*math.cos(angle),y+i*math.sin(angle) if (14 <= X <= 24) and …

Total answers: 1

Why is my function only splitting the last line in a data file?

Why is my function only splitting the last line in a data file? Question: I’m supposed to be writing a function that will read data from a .txt file and build a dictionary. The headers of the txt file will be the keys, and the values under each header will be values assigned to each …

Total answers: 1