4
answers
1
watching
169
views

 

program and see what happens so please enter your message so we get this message now. What we want to do is display this message for as long as the user remains in our program. So we use the while loop so we type while True which means while the condition is True. So In this case the condition is that our message variable is not empty and that 's why we put a comma after while because that 's what tells Python to keep looping while this condition is met okay now if you type exit out of our program right now you will get an error message because our while loop condition is not met Okay. So now let's add a counter to our program. So we can keep track of how many times our while loop condition has been met. So we add a variable called counter and set it to 1. Now if you run our program again and type exit out. of it, you will see that our while loop condition has been met four times. Now Let's add another counter and set it to 2 now. If you run our program again and type exit out of it. You will see that our while loop condition has been met six times now let's add another counter and set it to 3. Now If you run our program again and type exit out of it, you will see that our while loop condition has been met nine times now finally let's add another counter and set it to 4. Now. If you run our program again and type exit out of it. You will see that our while loop condition has been met 12 times. So this is how we can use the while loop in Python to write a value to the user. So next time I 'll show you how to read values from the user and how to write values to the user. THe passage discusses how an error occurred in a program. THe error was caused by attempting to subtract a string from an integer, which Python does not support. TO solve the problem, the author converted the string to an integer and solved the problem.. function is the string that we got from the input function now let's run the program so 10 and 20.1 and here 's the result In. This passage, the author explains how to solve a problem in Python where two numbers are being combined together as strings.. THe first number is read into a variable, and the second number is read into a second variable.. THe sum of the two numbers is then calculated using the float function, which converts both numbers to their. numeric representations. Finally, the sum of the two numbers is displayed on the terminal. One way to solve This problem would be to use the int function, which would convert both numbers to integers. However,. Since we're dealing with strings, we need to use the float function instead. Additionally,. Since we're not required to use the float function, we could have just called it at the time. We wanted to calculate the sum of the two numbers. IN conclusion,. This passage provides some insights into how to solve a problem in Python where two numbers are being combined together as strings.. The first step is to read in the first number into a variable, and the second step is to read in the second number.. The sum of the two numbers is then calculated using the float function, which converts both numbers to their numeric representations.. Finally, the sum of the two numbers is displayed on the terminal..

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in