#not defined not working

42 messages · Page 1 of 1 (latest)

fast pelicanBOT
#

@hard axle

ANDREW Uploaded Some Code

My guys , i made a python program , but in the program the not defined section is not working. Here is the python file

Uploaded these files to a Gist
hard axle
#

Can anyone tell me why isn't it working

fiery moat
#

Same problem as you had in your other help channel but with the letters

#

if number2 == 'a' or number2 == 'b' etc.

fiery moat
#

Nice

hard axle
#

Now i have another problem

#

Can u help

fiery moat
#

Is it the type stuff or something else?

hard axle
#

Nope something else

#

I set if input is equal to number then print a and when input is equal to latter print b and when input equal to anything else print c

#

But when i input anything else then latter it still shows b

#

The c part don't work

fiery moat
#

Can you share the code?

hard axle
#

In the code
else :
new_number2 = "not defined"
this section is not working

fiery moat
#

Because you're checking the type. the type of "not defined" is str

hard axle
#

Ik

fiery moat
#

So change elif type_number1 == "not defined" or type_number2 == "not defined": to use new_number1 and new_number2

hard axle
#

elif type_number1 == "not defined" or type_number2 == "not defined":
print("error , input is not a number or latter")

fiery moat
#

I'm not sure how much feedback you want on all of this but it could be rewritten in a better way as wang tried to explain in your help channel

hard axle
#

How

fiery moat
#

How what?

hard axle
#

Ok but i just completed it , it has only one problem

hard axle
fiery moat
#

Can you reshare what code you have now?

hard axle
#

Ok

#

Wait

fast pelicanBOT
#

@hard axle

ANDREW Uploaded Some Code
Uploaded these files to a Gist
fiery moat
#

What are you expecting to happen? The code seems to be doing what you've asked it to do

#
$ py sum.py
write any two numbers to sum them
write your first number:
5
write your secound number :
4
sum of 5 and 4 is 9

$ py sum.py
write any two numbers to sum them
write your first number:
a
write your secound number :
b
sum of latters cannot be found

$ py sum.py
write any two numbers to sum them
write your first number:
not defined
write your secound number :
not defined
error , input is not a number or latter
#

I really think you should look into what wang suggested

hard axle
#

Ok , so u typed not defined then it is showing not defined

#

I want if someone used anything else then latter and number it should show not defined

#

Eg if someone uses
--₹-₹-:_
Theses latter's it should say not defined

fiery moat
#

The problem is that's still a string

hard axle
fiery moat
#

Yeah, do what wang suggested 😅

hard axle
#

Ok

#

A much better way is to use in, or the built in isdigit, isnumeric, or isdecimal

#

They r models