Jul 26, 2008

Need Help With My Python Programs - just extremely basic stuff

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Others
Pages: 1, 2

free web hosting

Need Help With My Python Programs - just extremely basic stuff

arcanistherogue
ok, i am learning python, and i realy dont know much. my guide im using said to make a program where it asks your name, and if the name is yours your make it so there is a compliment, if it is another name you make it that its an insult, and anything else makes it say Nice name.

here is what i wrote

name = raw_input("What is your name?")
if name == John:
print "Your name is freaking sweet, you must be a god or something."
elif name == Bob:
print "You have a freakin' weird name, dude."
else:
print "Nice name,",name


i donot understand what i am doing wrong, i get this error when i run it:

What is your name? John

Traceback (most recent call last):
File "C:/Python23/name.py", line 4, in -toplevel-
if name == John :
NameError: name 'John' is not defined

can someone help me please?

thanks for any response.

Reply

arcanistherogue
bump... please, i need some help with this....

Reply

bjrn
Uhm, perhaps you need to add quotes around "John" and "Bob" in the if statement?

Reply

arcanistherogue
by God.. it worked!

you. cookie. now.

Reply

bjrn
CHOMP CHOMP CHOMP.

Very understandable error. Just like forgetting ';' in languages that need it (PHP, Java and so on). I'm just glad you hadn't got to somewhere where you had made hundreds of lines of code (and posted here) tongue.gif

I'm glad I could help and good luck with the further learning smile.gif

Reply

arcanistherogue
thanks alot.

right now im working on a math helper program, that has a list of many formulas. It will start out as a list of basic things, like area, etc, then when you select one it goes more in depth, like area of a quadrilateral, then maybe like area of a square or whatnot. what i want to have it do is to have a loop back to the main page after each formula, and i put if selection == 0 it displays the main screen, and all of the formulas have a number near them so you input the corressponding number to select the certain formula. what i want to know is, this is a basic idea of what i have, i want to know if it will work:

selection = 0
if selection ==0:
print "choose a formula"
print "1. area"
selection = raw_input
if selection == 1:
print "a. area of a square"
selection = raw_input
if selection == a
a = raw_input("Length of a side?")
b = a*a
print b
selection = 0

will that work? like will it loop back at the end of the formula?

and also, can i have multiple If's, or do i just put in multiple elif's?

 

 

 


Reply

bjrn
QUOTE(arcanistherogue @ Feb 7 2005, 10:30 PM)
and also, can i have multiple If's, or do i just put in multiple elif's?

I have to admit that I know very little about Python, so I don't really know how it would work if you wanted it to jump back to the beginning sometimes.

What I can tell you is that you shouldn't use elif's for the bit that you've written so far, once you have some more options on each level you can do that. But those if's you have at the moment should stay if's, because they are conditions that shouldn't be checked before the if before them has been checked.

Reply

s243a
I agree with what the above poster said. I find case neater but some books suggest avoiding it. I don’t know if python has a case. If not use else if although you could just as well use if. It is just less efficient and perhaps less readable. Also if you mathhelpers become long it is better to make them functions. On a side note I thought python was a functional programming language. From the code you showed me it looks like an imperative language like c.

Reply

iGuest
python
Need Help With My Python Programs

Hi,

I am very new to python.I need to write a program for a cluster.
Imagine a situation where there are three machines A,B,C clustered in a domain.If one machine goes down the other two should get notified by a message/email.Is it possible to write a script for that??Please help

-question by Kalpana

Reply

iGuest
basic program
Need Help With My Python Programs

Hello, I need help! I worte this

Name = raw_input("What is your name?")
If name == "Mario":
Print 'Hello, thats a beautiful name!'
Else:
Print "Hi, nice name,",name

I do not know whats wrong and it keeps on giving me errors,

Treaceback <most recent call last>:
File "<stdin>", line1, in <module>
Import Error: No module named name

I will appreciate any help!
Thank you
Marsal

-question by Mario

Reply

Latest Entries

iGuest
Case of letters
Need Help With My Python Programs

Replying to Trap FeedBacker
The problem with your program is most like the upper case in the original variable "Name". After the first line you type name with a lowercase. Python is very very case sensitive. So if you just replace the first Name with a lowercase name it should work. So it will look like this.

Name = raw_input("What is your name?")
If name == "Mario":
Print 'Hello, thats a beautiful name!'
Else:
Print "Hi, nice name,",name

-reply by Zemeus

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Recent Queries:-
  1. how to write basic python program - 17.50 hr back. (1)
  2. basic python program - 29.29 hr back. (1)
  3. programs made with python - 36.80 hr back. (1)
  4. python negative number validation - 64.20 hr back. (1)
  5. python basic program - 79.03 hr back. (1)
  6. python for loop in formula -vba - 111.48 hr back. (1)
Similar Topics

Keywords : python, programs, extremely, basic, stuff

  1. Python
    (1)
  2. Python
    another programming language (8)
    There are so many languages used in software and web development. Python is one of them. Basically
    Python is object-oriented , high-level programming language with dynamic semantics. Python was
    developed in the 90’s. Python is simple and easy to learn. Therefore it reduces cost of program
    maintenance. It is very attractive for rapid application development because of its high-level
    built-in data structures, combined with dynamic typing and dynamic binding. Python is also use as a
    scripting or glue language to connect existing components. Python supports modules and ....
  3. [pygame] Python Game
    (4)
    On this tutorial we will see how to draw a circle on the screen and move it around using the arrows
    of the keyboard. (Don't worry if you don't get anything, the code will be analysed line by
    line) CODE #!/usr/bin/env python import pygame from pygame.locals import * if not
    pygame.font:     print 'Atention, there are no fonts.' if not pygame.mixer:
        print 'Atention, there is no sound.' pygame.init() red = (255, 0,
    0) black = (0, 0, 0) window_width = 640 window_height = 480 window = pygame....
  4. Python Manace: Control Flow I
    python tutorial (3)
    Hello This is the first part of my Python tutorial. The code is pretty self-explanatory so few
    comments should be enough. If not - let me know. Tutorial assumes that You have already Python
    installed. Python 2.4 should be enough. Let's go, then. #! /usr/bin/env python # -*-
    coding: utf-8 -*- import math def squareRoot_1( lst ) : """Returns list of square
    roots. No negative number validation. Allows fractions in result.
    """ result = for el in lst : sqrtFloat = math.sqrt( el ) ....
  5. Python
    Programming Language (4)
    Does anybody else know any python? I've started learning it, because I heard somewhere that it
    is quite easy to learn and I want to learn a programming language quickly /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. I haven't learned how
    to do any complex stuff with it yet, but its still fun learning about it /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. If you want to find out
    more info about Python, then you can go to their website. I'm not sure if i'm allowed to
    post links....
  6. Password Generator
    Made in Python (9)
    This is a Password Genorator i made in python use Tkinter as the GUI. I will Compile it soon so
    people with out Python can use it. here is the source code CODE import random, math from
    Tkinter import * root=Tk() root.title("PassGen") length = Label(root,
    text="password length:") length.pack() input = Entry(root,
    text="8") input.pack() input.insert(0, "8") units =
    "abcdefghijkmnopqrstuvwxyz0123456789" password = Label(root,
    text="password:") pas....
  7. Fib Gen In Python
    (1)
    OK this is one of my first programs.. from Tkinter import * CODE def NextNumber():
        count = 0     x = 0     y = 1     while count <= int(Range.get()):
            for item in [x]:             listbox.insert(0, item)         z = x
            x = z + y         y = z         count = count + 1 root = Tk() Title =
    Label(root, text = "Calculate fib number:") Title.pack() Range =
    Entry(root) Range.pack() PrintNextNumber = Button(root, text = "   Display  
    ", ....
  8. How Do I Create Programs?
    (17)
    how do i create programs like, a browser, or a sible program that is a calcualor ect. how do i make
    toolbars and things like that? -Microsoft Lack of content and missing topic description.
    Warning! ....
  9. Delicious + Gmail
    python (2)
    I stumbled upon this link earlier today and was hoping someone could explain or walk me through
    getting the script running. http://ponderer.org/del.icio.us I'll keep the post short since I
    have no clue as to what I should. I'll just say that I rarely work on WinXP and I would rather
    get it running on my old win box sitting in the corner. ....
  10. Ok, So I'm Learning Python...
    (3)
    I was wondering, can I make games in python, even simple text based ones? me and my friend wanted to
    start making homebrew games, and we decided to start out learning python. I've learned a bit,
    not much, but enought to make one of those conversations with the computer, like with loops and
    where they ask questions like "what is your name?" and then say it back etc. We plan on also
    learning C++, which we will learn later after we get real good with Python. However, will I
    eventually be able to make games with Python?....

    1. Looking for python, programs, extremely, basic, stuff

Searching Video's for python, programs, extremely, basic, stuff
advertisement



Need Help With My Python Programs - just extremely basic stuff



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE