Forum Thread: Python Beginner Scripting?

Python Beginner Scripting?

Ok so , I'm trying to make a very very very simple Python 3.4 program because I'm just starting out, so please try to dumb things down for me, so the program just asks you for your name and asks you what's 2+ 2, it goes like this

x = rawinput ("what is your name?")
Print ("nice to meet you" + x)
Y = Raw
input ("what is 2+2?")
If y = 4: print ("great job")

Am I doing this right? What if the user enters somthing like 10 how do I tell the script that if he enters any other digit than 4 to say "wrong! Please try again" and loop the same question

This is my second day learning Python with 0 programming experience
So please dumb stuff down for me thanks ;D

17 Responses

Not really 0 scripting experience. It very minimal

There are many ways to tell the user that it's not right. The easiest example is an if/else statement

Thanks, how come there's 2 == not 1? And after the 4 you put : ?

One equal sign is used to assign variables. If you are comparing things, you use two.

While using a conditional statement, the equal operator is two equal (=) signs

Ok thanks man :D 1 more question and I promise it'll be my last, how do I make it if he gets it right it moves on to what's 2 + 3 and if it's wrong it repeats the same question

The easiest way would probably be a while loop. It is as follows (this is only pseudo-code)

Also, questions are fully welcome! Feel free to ask more!

Alright thanks man your awesome I'll try it and see how it goes :D

Keep in mind that you are asking the user for a string value and than comparing it with a numeric value. To get rid of errors.

If y = 4: print ("great job")
If int(y) == 4: print ("great job")

Hope This Helps!

  • Cameron

I totally forgot about that!

What does int mean?

Int stands for integer. Meaning any whole number.
Example: 1, 2, 3, 4, 5

Here are some others in python to help you out:

Str stands for string. Meaning any line(s) of text within quotes ""

Example: "The big brown fox jumped over the lazy dragon."

Float stands for float. Meaning any fraction of a number.

Example: 1.5, 3.14, 8.2

One thing that many beginners have a lot of trouble with is boolean values.

You can specify a boolean by typing bool() and in between the parentheses a true or false statement. Here is a line of python code that will print the boolean value, true.

print bool(2+2==4)
(keep in mind that the double '=' sign means is equal to, and a single equals sign assigns values to variables.)

The outcome of this statement will print:


I hope this helps quite a bit!

  • Cameron

thanks man youre awesome, everyone that helped me out is awesome !

x = rawinput (" whats your name: ")
print (" hey how are you " + x)

y = rawinput ("whats 2+2")
if (int)y == 4: print (" great job ")

keeps saying syntax error and highlighting the y

yayay !!! it worked

First off, I am pretty sure rawinput is no longer supported in Python 3.4 Just use input to make things simpler.

name = input ("what is your name?") #It's better to make your variables mean something, which becomes useful for when you are dealing with large chunks of code

Print ("nice to meet you" + name) #prints the string and the variable
question = input ("What is 2+2?") #asks user input
if int(question) == 4: #if the input is an integer that is exactly 4, it continues
(indent this) print("Correct!") #prints correct

Hope I helped some.

Share Your Thoughts

  • Hot
  • Active