Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with while cicle
#1
Hi everyone,
I am a neophyte and am still studying the basics. I am following a tutorial online about how using while to create a calculator software. The teacher suggested this code:



_________




hello_mex = """Hi! I am your virtual calculator!

Here are the available functions:
- if you want to perform an addition, select 1,
- if you want to perform a subtraction, select 2,
- if you want to perform multiplication, select 3,
- if you want to perform division, select 4,
- if you want to perform an exponential calculation, select 5,
- if you want to perform a square root, select 6.
- To exit the programme you can press Esc.

while True:
    print(hello_mex)

    action = input("Enter the number corresponding to the operation to be performed: ")

    if action == "1":
        print("\n You chose: addition.\n")
        add_1 = float(input("Write the first number. "))
        add_2 = float(input("Write the second number "))
        print("The result is  " str(add_1 + add_2))

    new_action = input("\nDo you want to proceed with another function? Y?N ")
    if new_action == "Y" or new_action == "y":
        print("I am coming back to the menu'")
        continue
    else:
        print("See you!\n")
        break 
Unfortunately, everything stops when I have to insert the number related to the function to be selected and if I press number 1, it starts again with hello_mex.

Could someone please help me?? I am getting crazy!
Thanks
Larz60+ write Sep-15-2024, 09:10 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
tags added for you this time. Please use BBCode tags on future posts.
Reply
#2
You are missing closing quotes for the hello_mex string, and line 21 is missing a comma. Once I fixed those, the program works as expected. I don't think you posted the code you are running.
Astelen likes this post
Reply
#3
(Sep-16-2024, 02:24 AM)deanhystad Wrote: line 21 is missing a comma.
not really
>>> print("foo" "bar")
foobar
Otherwise, you are right
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020