Python, writing multi line code in IDLE

2019-01-25 19:07发布

How do i write

   >>> x = int(raw_input("Please enter an integer: "))
    >>> if x < 0:
    ...      x = 0
    ...      print 'Negative changed to zero'
    ... elif x == 0:
    ...      print 'Zero'
    ... elif x == 1:
    ...      print 'Single'
    ... else:
    ...      print 'More'
    ...

this in IDLE. As soon as I hit enter after writting first line, it executes the first line and i am not able to write full code. I am very new to python, just started it today. Any help will be appreciated.

4条回答
倾城 Initia
2楼-- · 2019-01-25 19:52

1: Use semicolons between lines
2: Try iPython
3: Write it as a function, e.g.

def myfunc():
    x = int(raw_input("Please enter an integer: "))
    if x < 0:
        x = 0
        print 'Negative changed to zero'
    elif x == 0:print 'Zero'
    elif x == 1:print 'Single'
    else:print 'More' 
查看更多
乱世女痞
3楼-- · 2019-01-25 19:54

Try File => New Window in top menu. Then write your code in this windows and run it by F5 key (or Run in top menu)

查看更多
不美不萌又怎样
4楼-- · 2019-01-25 19:55

Shift + Enter takes you to next line without executing the current line.

查看更多
家丑人穷心不美
5楼-- · 2019-01-25 20:06

Can't write multi-line code in python console. Need a 3rd-party app.

查看更多
登录 后发表回答