Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JocelynC

  • one year ago

Hi. I just started the 6.00 Computer Science course, and I have a small programming issue. I tried to type the professor's code used in the lecture manually (the PDF for the link failed) and only the first part to the program showed. What I typed: x = int(raw_input('Enter an integer ')) if x%2 == 0: print 'Even' else: print 'Odd' if x%3 != 0: print 'And not divisible by 3' What it gave me: Enter an integer When you enter an integer, the program finishes. Nothing else happens. What is wrong? I know the exclamation point is likely incorrect...

  • This Question is Closed
  1. JocelynC
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Additionally, whenever I insert a premade program into python that has 2 lines (input, assignment) only the print section of the program works. Nothing else. For example, in this premade program: name = raw_input('What is your name?\n') print 'Hi, %s.' % name It says 'what is your name' but stops there.

  2. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    The only problem that I see in your first program is that the 2 lines dealing with three shouldn't be part of the else block. It's interesting that both programs have an issue with raw_input(). Are you using Python v3.x? AFAIK, the course requires Python v2.x.

  3. JocelynC
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm using 2.5.4. Is that not the correct verson? This is what happens: >>> x = int(raw_input('Enter an integer ')) if x%2 == 0: print 'Even' else: print 'Odd' if x%3 != 0: print 'And not divisible by 3' Enter an integer 23 >>> What do you mean by "the three should not be part of the else block?"

  4. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    2.5.4 is the recommended version for the 6.00 course from 2008. There's a 6.00 course from, I think, 2010, and I'm not sure which version that recommends. What I see in your reply is that you're not putting this code in iDLE, but in the shell, which is geared mostly toward single line commands: >>> x = int(raw_input('Enter an integer ')) Enter an integer 5 >>> print x 5 >>>

  5. JocelynC
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    How do you put the code into idle? The download only came with two things: the shell, and a black window, as well as a guide. Does iDLE need to be downloaded separately?

  6. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    Actually, you don't HAVE to have iDLE. I don't use it because it was changing my tabs to spaces and giving me errors. You need to put this code into a plain-text editor. Examples would be notepad on PCs, TextEdit can be used on Mac, but you have to be careful when you save it. The editor that comes with Adobe CS, XCode. And the command line editors vi, emacs and nano. Then you can execute with a command like: python myprogram.py. This was a way to quick intro to this stuff.

  7. JocelynC
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ohhh. I get it. You have to execute the program by using F5. IDLE is just a sort of notepad-like thing that automatically tabs for you and hilights. Thanks much for your help! I'll probably need it in the future :D

  8. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    Feel free.

  9. michaelokt
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    open python shell gui. on top, click file, then new window. type code. file, save as. save with.py after the name of the file. close all python windows, open python shell gui again. file, open, find ur file. to execute, press f5 and save changes. the results appear in the shell window.

  10. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.