Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding understanding help
#1
Hallo

I'm very new to coding, so it's is maybe a silly question

I have of piece of code, i don't understand

My code her
def Halloworld(Mystring):
    print (Mystring)
    MyName = input ("what's your name?")
    MyVar = input ("Enter a Number")
    if(MyName == "kas" or MyVar != 0):
        print("kas is great")
    elif(MyName == "bob"):
        print("you are okay")
    else:
        print ("Hallo you")
    
Halloworld("Hallo function world")
When i run the code for eks.
Output:
Hallo function world what's your name?bob Enter a Number1 kas is great
when i enter the name bob and the number 1, i'ts says kas is great
shouldn't it's say bob, you are okay?? because the != operator it is false, and the == "kas" is false
Reply
#2
MyVar is 1. So it is not equal to 0. So MyVar != 1 is true, not false.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thanks for clearing that up for me ichabod801
Reply
#4
MyVar is a str returned by input, it needs to be converted to a number by using int to make the comparison from one number to another instead of a str to a number.
Reply
#5
Hi Yoriz

I'm very new to codeing, just startet today:)

Do have some links Example for using the int?
So i have some read up things for tomorrow
Reply
#6
Try running this code:

print('1' == 1)
print(1 == 1)
print(int('1') == 1)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 1,765 May-09-2023, 08:47 AM
Last Post: buran
  Coding understanding help srikanth 1 1,462 Jul-19-2019, 09:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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