Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If Statement Help
#6
(Jul-30-2019, 01:11 PM)metulburr Wrote:
(Jul-30-2019, 12:56 PM)VictorVictus Wrote: if is_male and name: "Connor"
This is not doing what you think it is doing. I would highly suggest to read through out common pitfalls as well as validating user input

Quote:
if is_male and name:
This is what you have. This if condition will always execute because of name. It will always have content in it from the user input (unless the user just hits enter instead). It does not mean if name equals conner...for that you need
if name == "Conner":
Also as added advice. Your second if condition could simply be an else clause due to it being the opposite if the initial if condition. Also you should not concatenate your strings like this. It is not pythonic.
Quote:print("My name is " + name + "")
You should use python format or f-string of python3.6+
print("My name is {}.format(name))
f-string
print(f"My name is {name})

Thank you for your kind help! Big Grin Unfortunately, I've not managed to understand a single thing you said :(. Regardless, many thanks! If you could point me in a way to learn more stuff about Python I Will be heavily thankful.
Reply


Messages In This Thread
If Statement Help - by VictorVictus - Jul-30-2019, 12:56 PM
RE: If Statement Help - by cvsae - Jul-30-2019, 01:03 PM
RE: If Statement Help - by VictorVictus - Jul-30-2019, 01:12 PM
RE: If Statement Help - by cvsae - Jul-30-2019, 01:13 PM
RE: If Statement Help - by metulburr - Jul-30-2019, 01:11 PM
RE: If Statement Help - by VictorVictus - Jul-30-2019, 01:19 PM
RE: If Statement Help - by metulburr - Jul-30-2019, 01:21 PM

Forum Jump:

User Panel Messages

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