Just starting out....

This is the place for queries that don't fit in any of the other categories.

Just starting out....

Postby stevenjwilliams83 » Wed May 21, 2014 1:41 pm

Hello folks -

I am just starting out in the world of python. I have basic knowledge of coding in vb.net and java. I understand logic, but struggle with syntax.

I am trying to play around with my first program and struggle with verification methods within the program.

Code: Select all
# This program will take the input of a users name
# and greet them with a hello!

name = raw_input('What is your name?\n')


print "Hello, " + name


response = raw_input('How are you today?\n')

print "I am glad that you are " + response


favnum = raw_input('What is your favorite number?\n')

print "Do you know what " + favnum + " times 5 is?"

mathinput = int(favnum) * int(5)

print mathinput


I am looking for what I believe is going to be if, then, else structures. I want to verify that when a user inputs a "name" when asked that it is a string, not an numeric value.

I also want to verify that when they enter their favorite number it is a int, not a float. This isnt complete yet, but essentially I would want the user to enter their favorite number, then the question be asked what that number is * 5 then allow for input, then do a if, then, else statement again to verify their answer is correct.

Can someone give me some guidance?

Thanks.
Last edited by micseydel on Wed May 21, 2014 8:00 pm, edited 1 time in total.
Reason: Code tags, lock.
stevenjwilliams83
 
Posts: 2
Joined: Wed May 21, 2014 1:36 pm

Re: Just starting out....

Postby stevenjwilliams83 » Wed May 21, 2014 2:46 pm

Updated Code:

Code: Select all
# This program will take the input of a users name
# and greet them with a hello! Then take their favorite
# number andmultiple it by 5, then verify answer.

name = str(raw_input('What is your name?\n'))


print "Hello, " + str(name)


response = raw_input('How are you today?\n')

print "I am glad that you are " + response


favnum = int(raw_input('What is your favorite number?\n'))

while favnum < 0:
        print "Invalid, Value must be positive\n"
        favnum = int(raw_input('What is your favorite number?\n'))

else:     
    question = raw_input("Do you know what " + str(favnum) + " times 5 is?\n")







                   
stevenjwilliams83
 
Posts: 2
Joined: Wed May 21, 2014 1:36 pm

Re: Just starting out....

Postby Kebap » Wed May 21, 2014 2:53 pm

Hi steven, welcome to the show! :mrgreen:

You are maybe looking for a python tutorial like How to think like a Computer Scientist:

http://interactivepython.org/courselib/ ... -selection

It is a great book, too.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 390
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests