Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,854 members, 7,810,284 topics. Date: Saturday, 27 April 2024 at 05:26 AM

Help! I Need Guidance On This Problem In Python - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help! I Need Guidance On This Problem In Python (433 Views)

Practical Guidance On SQL And Power BI For Pursuing A Career In Data Analysis / Please Help Me Solve This Problem In C++ / Who Wants To Learn Programming In Python Easily Without Stress? READ THIS (2) (3) (4)

(1) (Reply) (Go Down)

Help! I Need Guidance On This Problem In Python by Enny007(m): 12:48pm On Apr 01, 2022
I am an absolute beginner in python, I started learning python just two weeks back and I decided to take up a project I think of in my brain and work on it using the information I have been able to gather so far, but at this junction am confuse and I need help.

The problem am encountering now with the python program image attached to this post is that;

after the "while true" statement, I will like to ask the users their name, then they can now move to the next line code in the loop, but what I discovered after running the code is that, after the user has input their name and about to move to the next line of code, the command line asking user to input their name will be showing again and am confuse on what to do.

which is the reason why I use the >>>>>>> to test it, it works but that's not what I want, I want the user to be able to enter their name before moving to next line of code.

I will appreciate if anyone can help. Thanks

Re: Help! I Need Guidance On This Problem In Python by shegzhkn: 2:31pm On Apr 01, 2022
.
Re: Help! I Need Guidance On This Problem In Python by Onewazobia(m): 3:04pm On Apr 01, 2022
A brother studying mechatronics in one of our public university is seeking advice were to start from in pursing career in programming.
Please note I'm novice on this that's why I could not advice him appropriately. So, tolerate my mixup.
Python, Java, Matlab, Coding,etc. which of this should be his starting point secondly physical training person/center in Lagos preferably Ikeja area
Please help forward this to the front
Re: Help! I Need Guidance On This Problem In Python by Enny007(m): 4:25pm On Apr 01, 2022
shegzhkn:
First o all their is a lot of holes in ur code.

I will tell you where the problem is what's the ball your loop you put a true as the condition meaning it is going to be running for ever and then in the body there is no code that will terminate it at some point so your code is going to run infinitely so what you need to do in the body is to put the break statement and it will terminate the loop.

Thank you for your reply. are you suggesting I should use the "break statement" after the first line and continue.
and also how should I continue the code.

Thanks.
Re: Help! I Need Guidance On This Problem In Python by Abra4real(m): 7:24pm On Apr 01, 2022
Enny007:
I am an absolute beginner in python, I started learning python just two weeks back and I decided to take up a project I think of in my brain and work on it using the information I have been able to gather so far, but at this junction am confuse and I need help.

The problem am encountering now with the python program image attached to this post is that;

after the "while true" statement, I will like to ask the users their name, then they can now move to the next line code in the loop, but what I discovered after running the code is that, after the user has input their name and about to move to the next line of code, the command line asking user to input their name will be showing again and am confuse on what to do.

which is the reason why I use the >>>>>>> to test it, it works but that's not what I want, I want the user to be able to enter their name before moving to next line of code.

I will appreciate if anyone can help. Thanks

I'll be painfully honest with you: your code has a lot of bugs. The first one I see is your creating a global variable "User_input" and then, recreating it in the while statement. Totally unnecessary.

Let me check your code again and suggest ways you can do this.
Re: Help! I Need Guidance On This Problem In Python by Abra4real(m): 7:30pm On Apr 01, 2022
Enny007:
I am an absolute beginner in python, I started learning python just two weeks back and I decided to take up a project I think of in my brain and work on it using the information I have been able to gather so far, but at this junction am confuse and I need help.

The problem am encountering now with the python program image attached to this post is that;

after the "while true" statement, I will like to ask the users their name, then they can now move to the next line code in the loop, but what I discovered after running the code is that, after the user has input their name and about to move to the next line of code, the command line asking user to input their name will be showing again and am confuse on what to do.

which is the reason why I use the >>>>>>> to test it, it works but that's not what I want, I want the user to be able to enter their name before moving to next line of code.

I will appreciate if anyone can help. Thanks

Okay, I have checked your lines of code. Here is where the problem is: you do not understand what "while statements" are used for. While statements are used to execute a line o more o code if a condition is met. In your code, you used "while True" which means that the condition will always equal True and the code will keep executing in an endless loop. grin

I could write you lines of code to help you do what you want to do, but that will not help you. Go and learn this thing from a proper place, bro. I recommend w3schools.com

I am living testimony that the simplistic method of W3Schools actually grounds you.

2 Likes

Re: Help! I Need Guidance On This Problem In Python by shegzhkn: 12:23am On Apr 02, 2022
.

2 Likes

Re: Help! I Need Guidance On This Problem In Python by Jaguarspaw: 6:11am On Apr 02, 2022
while True:
user_input = input("Please enter your name:"wink
print(f"Hello {user_input}, what do you want to learn
today"wink
# if the conditions below are not met, the loop starts allover without the break statement

if user_input == "O":
print("blabala"wink
elif user_input == "S":
print("blabla_2"wink
# you should break the loop
else:
break


Another scenario

Probably the len of user_input must not be less than 3 characters

while True:
user_input = input("Please enter your name:"wink
if len(user_input) < 3:
print("You need to input a name with more than 3 characters"wink
continue # returns to get user input
else:
print(f"Hello {user_input}, what do you want to learn today"
break #breaks the loop
Re: Help! I Need Guidance On This Problem In Python by bedfordng(m): 1:55pm On Apr 02, 2022
Your code is moving to the next line but you just can't notice since there is no break statement.

All you need to fix this is to add a break statement after the print under the if statements.

Also you might want to add an if statement to check if users enter something.

1 Like

(1) (Reply)

Is Javascript Really Bad For Data Structure And Algorithms Practice / Project Based Learning (FULL-STACK DJANGO DEVELOPER) / Flash Oppo Realme 1 Model 1859

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 25
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.