need some help

Oatmar

just beachy
Contributor
Joined
Mar 30, 2016
Messages
64
Reaction score
114
Points
358
Location
not the beach
Gender
Female
my husband is trying to write a simple python program to check user input. 1 for letters vs numbers. 2 for it to be binary 11001100 vs 12345678 getting really stuck on the binary check
I don't know anything about it, but many of you fine folks might be able to help so he has asked me to ask you
 
  • Like
Reactions: LastBorn Jnr

Tjololo

Active Member
Joined
Jan 12, 2016
Messages
629
Reaction score
2,628
Points
493
Age
36
There's a few ways to accomplish what you're looking for. I don't want to give the answer away, because learning how to look for the answer is a huge part of learning programming. I'll give the following hints:
  • There is a programming concept called "casting", where one datatype is changed to another datatype. The conversion will fail if the destination data type is not compatible with the input (for example, "1.0" could be converted to an integer, but "Apple" could not)
    • You can find the datatype of a variable using python's "type()" builtin function
  • If a cast fails, it throws an exception
Since he's looking specifically for binaries, and it looks like he's got the letters vs numbers figured out, I'll give one more hint for the binary check:
  • Python's "int()" function takes two inputs
If he's still stuck, here's a potential solution. But please have him try to figure it out without peeking, he'll learn a lot more that way.

Log in or register now. to view Spoiler content!
 

Oatmar

just beachy
Contributor
Joined
Mar 30, 2016
Messages
64
Reaction score
114
Points
358
Location
not the beach
Gender
Female
thank you so much! i will pass this on to him

eta: he says "thank you, I did manage to figure it out.
I was looking at it to hard. Compared to what i have learned [your] suggestion is very advanced.
 
Last edited:
  • Like
Reactions: LastBorn Jnr

Tjololo

Active Member
Joined
Jan 12, 2016
Messages
629
Reaction score
2,628
Points
493
Age
36
thank you so much! i will pass this on to him

eta: he says "thank you, I did manage to figure it out.
I was looking at it to hard. Compared to what i have learned [your] suggestion is very advanced.
Yeah, I wasn't sure what his skill level was. There's many different ways to accomplish that goal, that was just one of them.