while-loop

Transform For loop into while loop

Transform For loop into while loop Question: s=0 for i in range(3,20,2): if i>10: break else: s=s+i print(s) how can i transform this code into a while loop? I don’t know how to include the step. Asked By: maria carolina || Source Answers: s = 0 i = 3 while i<10: s+=i i+=2 print(s) Answered …

Total answers: 4

How to check if the first line has changed in a text file using python

How to check if the first line has changed in a text file using python Question: I’m trying to write a script that will check if the first line of a text file has changed and print the value once. It needs to be an infinite loop so It will always keep checking for a …

Total answers: 2

Python while not true loops

Python while not true loops Question: door = input("Do you want to open the door? Enter yes or no: ").lower() while door != "yes" and door != "no": print("Invalid answer.") door = input("Do you want to open the door? Enter yes or no: ").lower() if door == "yes": print("You try to twist open the doorknob …

Total answers: 2

What exactly is Stop in this question and how do I get the sum?

What exactly is Stop in this question and how do I get the sum? Question: Problem Statement Edit: I have transcribed the image as suggested although I think some terms are better shown in the picture if anything is unclear here; This function takes in a positive integer n and returns the sum of the …

Total answers: 4

Python How to break loop with 0

Python How to break loop with 0 Question: I don’t understand why is not working on my code def random_calculation(num): return((num*77 + (90+2-9+3))) while random_calculation: num = int(input("Pleace enter number: ")) if num == "0": break else: print(random_calculation(num)) Can you guide me what is wrong here, i really dont understand Asked By: Glonza || Source …

Total answers: 2

For loop monthly budget program creating error

For loop monthly budget program creating error Question: I am running this for loop code and it is creating an error, I cannot find out the problem with it print(""" This program will prompt you to enter your budget, and amount spent for a certain month and calculate if your were under or over budget. …

Total answers: 2

How to create for loop for monthly budget program?

How to create for loop for monthly budget program? Question: I am trying to create a for loop program that prompts the user to enter how many months they want to monitor their budget for, prompts for the amount they spent during the month, and their budget. It should tell the user how much they …

Total answers: 1

Addition of integer input through while loop

Addition of integer input through while loop Question: I’m trying to create a while loops where you can input as many integers as you want. The input gets summed up and printed only when I type in the number 0. Currently I have written the following: n = int(input()) sum = 0 while n != …

Total answers: 1

How to print the updated output

How to print the updated output Question: I need help with my code because it doesn’t print the updated output For example: Enter First name: Cid Enter Middle name: RAZOR Enter Last name: Kamisato Enter number of subjects: 1 Please enter this valid subjects: [‘CC1’, ‘CC2’, ‘CC3’, ‘CC4’, ‘CC5’] Please enter the subject: cc1 **** …

Total answers: 1