#๐ how do i make it so if i say "Yes" or "yes" then it says the if statement instead of the else
276 messages ยท Page 1 of 1 (latest)
@vapid raft
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
and when you input anything other than "yes" or "no" then it says something like "Please answer the question" until you say yes/no
.lower is .lower()
if you want help with your code, paste it as text, not a screenshot.
and paste all of it, not just a little bit
looking at it, that might actually be all of it
did it help?
did the responses help?
oke
nah they want to loop until the user has entered 'yes' or 'no'
this part fixed the saying yes or no part
you need a loop
yes
... im aware, but fixing the first error is the first step
try to think how you would implement it
any ideas?
question2 = input (f"Is your name {question}? ")
while
if question2.lower() == ("yes"):
print("Your name is so cool!")
else:
print("That's not your name! You liar!")```
while something != True
it should be looping
when the condition has been met
make something == true
that's the hint
there needs to be a condition for it to loop continuously
and when the condition is false it should stop the loop
in your case you want to stop the loop when user has either entered a 'yes' or 'no'
!e
i = 5
while i > 0:
print(i)
i = i - 1```
@fiery spear :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 5
002 | 4
003 | 3
004 | 2
005 | 1
so like
!e question = input("What is your name? ")
question2 = input (f"Is your name {question}? ")
while question2 == True:
if question2.lower() == ("yes"):
print("Your name is so cool!")
elif question2.lower == ("no")
break
else:
print("Please enter (Yes) or (No)")
@vapid raft :x: Your 3.12 eval job has completed with return code 1.
001 | File "/home/main.py", line 6
002 | elif question2.lower == ("no")
003 | ^
004 | SyntaxError: expected ':'
You don't need the () around "no"
also python doesn't know if the answer is correct unless you tell it to so you can't do while question2 == True
how do i tell python that yes is the correct answer
when the user enters a valid answer you can change the value of a condition variable
!e
run_until_0 = True
i = 5
while run_until_0 == True:
print(i)
if i == 0:
run_until_0 = False
i = i - 1```
@fiery spear :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 5
002 | 4
003 | 3
004 | 2
005 | 1
006 | 0
do you see how that works
I am changing the value of variable run_until_0 to False when i = 0
you can do something similar when user has entered yes or no you can change some condition variable to False
i do not understand it
wait
Which part?
is anyone available to call so i can screenshare
and try explaining it to me like im a new born
nah my introverted ass heads out
Maybe somebody else might but I don't do that, sorry.
all good!
plus my English is poor
we can just do it in chat. tell me which part of the code do you not understand
Okay so
I dont understand how to make it loop after it asks the second question
while run_until_0 = True
This line checks if run_until_0 is True
if it is True then run the code inside the while loop
if it's false then don't run the code inside the loop
ok first start like this
make it while True
while True:
now run the code
what happens when you enter a wrong answer
u there?
@vapid raft
ok
question2 = input (f"Is your name {question}? ")
while True:
if question2.lower() == "yes":
print("Your name is so cool!")
elif question2.lower == "no":
break
else:
print("Please enter (Yes) or (No)")```
so you want to spam that until the user enters yes or no right
I want it to say that once
every time the user enters an answer that is not
yes or no
wouldnt this just infinitely print please enter (yes) or (no)
not in case of no
question2 = input("Please enter (Yes) or (No)")
put this in the else box instead
see what happens
ye
whenever i type no
it says please enter yes or no
and whenever i press yes
it infinitely says your name is so cool
also add a break after "yes"
don't spoonfeed
oki
i added () after the second question2.lower
and it broke the code without giving a message
post the code you have right now
what did you enter
the no works
question2 = input (f"Is your name {question}? ")
while True:
if question2.lower() == "yes":
print("Your name is so cool!")
elif question2.lower() == "no":
print("You lied to me!")
break
else:
question2 = input("Please enter (Yes) or (No) ")```
add a break in the yes one
the way that while True: loops work is that you have to stop them yourself
whenever i say yes though, it infinitely runs your name is so cool!
we want else: to update whatever is in the loop which we do by using input()
so i have to break the yes or it will run infinitely?
yes
and i have to break after the no as well or it will run infinitely?
yes
runs infinitely until you answer yes or no
whenever i put in something that isnt "yes" or "no"
i think it works!
awesome
question = input("What is your name? ")
question2 = input (f"Is your name {question}? ")
while True:
if question2.lower() == "yes":
print("Your name is so cool!")
break
elif question2.lower() == "no":
print("You lied to me!")
break
else:
question2 = input("Please enter (Yes) or (No) ")```
but usually break statement is not recommended, there are better ways to do the same
out of curiosity how would you do it @fiery spear
how could i do it instead of breaking
since i would link the while loop to some sort of variable most of the time
is there a way to shorten it?
not really
that's what I am referring to
also is there a way to make it so .lower() doesnt show on each and every single one
like can i use a nested loop to make it so everything in the nested loop is lower?
not shorter but better. shorter doesn't always mean better readability is important
from what i learned a nested loop is a loop in a loop
I would do
success = False
while not success:
if condition:
success = True
else:
(code)```
yeah i dont know that
It's a while loop with an if/else inside of it
yep
anything nested is broadly a "thing" inside of a "thing"
What MildlyPanda showed you wasn't a nested loop.
a dream within a dream
nested dreams
be me
self-reflection
find nested me
ok i think the question has been anwered here
off i go
i dont know the terms dictionary or function
but i think i get the general jist of how while loops work
now what is a for loop

there are plenty of nifty online videos that go over those basics of python
This course will give you a full introduction into all of the core concepts in python. Follow along with the videos and you'll be a python programmer in no time!
Click the โ๏ธ to change to a dub track in Spanish, Arabic, or Portuguese, or Hindi.
(Hindi dubbed via Melt Labs - https://www.withmelt.com/)
Want more from Mike? He's starting a codin...
this is the one i used, but feel free to play it at x2 speed since 4 hours is a little bit daunting
i dont like how he stares at me
slowing it down and rewinding in case you didnt catch something
but ill give it a go
dont worry there will be plenty of online sources filled with heaps of knowledge and computer nerds staring at you when you gain experience as a coder
i think i might be stuck on for loops for a little bit
alright ill quickly explain for loops
for loops accept many kinds of variables
strings, lists, and dictionaries for example
and it goes through every "element" of that variable
for example, in a string, the string is comprised off multiple letters
when you put that string in a for loop
what is a dictionary
a list is like this [1, 2, 3, 4, 5] right?
a string is ("text")
you get to assign another variable to each individual element
yes
yes
dont worry about it for now
nope
a dictionary is defined by curly brackets
dictionary = {}```
and inside of dictionaries you have a SINGLE key
and a corresponding value
for example 'yes' is my key
'nice' is my value
dictionary = {
'yes': 'nice'
}```
in this case it would be
dictionary['yes'] (which would give us 'nice')
i am confused
dont worry
watch the video and he'll give a more thorough explanation
or at least i would hope so if youre sitting through it for 4 hours
ok yeah for now just watch the video
Aye aye capn'
and save all your questions until after you've finished watching it
I'll see how far into the video I can get
I'm playing lethal with some friends in an hour or two so I don't think I'll have time to finish it tonight
when
i = 0
what is i
0 is an integer right?
what is i called in that situation
i is an integer right
i is a variable, and it's type is an integer
on the other hand
if i did
i = "0"
so variable =
= is always when you want to set a variable
True/False is what programmers call a boolean
and then i will be created as a variable
yes
and its boolean is true
yes
variable i = that list
so print(i) would print that list
print is used to print a variable or string?
print can be used to print anything
mhm
input makes something that you can reply to?
in the case of stuff like strings or integers it wont tell you what type the printed variable is
yep
and print would make the input visible
input() just "freezes" the code until it gets a response
so if i wanted to use a for loop
to print the alphabet
and stop at a certain letter
how would i do that
can you call so i can screenshare and say my thought process?
so you want to input the letter that is stops at?
you dont have to vc or use mic
sure
let me set up a google meet
where i live discord is blocked
is that okay with you?
Sure
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.