python 学习小记 - Breeze's Blog

python 学习小记

Breeze posted @ 2011年3月07日 22:37 in Linux编程 , 1915 阅读

最近学习python,看了几天书,今天想写一个小程序,感觉很难,好不容易写一行,还是错的,看书的时候感觉懂了,可是写起程序来还是不行,看来多写程序很有必要,附上今天写的小程序,继续努力!

#!/usr/bin/env python
num = raw_input('Enter num: ')
print
def testNum(num):
    num = int(num)
    if num < 60:
        print 'F'
    elif num >= 60 and num <= 69:
        print 'D'
    elif num >= 70 and num <= 79:
        print 'C'
    elif num >= 80 and num <= 89:
        print 'B'
    else:
        print 'A'
print testNum(num)

Avatar_small
纵横天下 说:
2011年3月08日 12:51

看来你用的是python 2.x!快换成 python 3.x 吧!

Avatar_small
Breeze 说:
2011年3月08日 15:20

@纵横天下: python 2.7,在读Python 核心编程(第二版)(Wesley J.Chun著),书中用的是python 2.4,
python 3.x与python2.x变化大吗?

Avatar_small
insraq 说:
2011年3月09日 00:59

3.x是不向下兼容的,最简单的一点:

print 'foobar' # print statement

变成

print('foobar') # print function

Avatar_small
纵横天下 说:
2011年3月09日 23:41

@Breeze: 虽然3.x不兼容2.x,但是奇怪的是2.x兼容3.x~~

@insraq: 还有raw_input变成input

Avatar_small
Breeze 说:
2011年3月10日 10:10

@纵横天下: 书总是要慢很多,跟不上。

Avatar_small
xinchao 说:
2011年3月12日 14:35

楼主,其实python并不难!它的语法部分我感觉是最简单的。不容易出错。但是,学习编程我感觉要把一种语言学的很熟,再去学习其他的。否则,很难进步。一家之言,共勉

Avatar_small
Breeze 说:
2011年3月12日 16:14

@xinchao: 非常感谢

Avatar_small
Emma 说:
2023年2月01日 22:10

It can be a challenge to learn programming languages like Python, but with determination and practice, you can develop diamonds rings near me your skills quickly. You should be proud of yourself for taking the initiative to write a program today, even though it wasn't successful. Writing programs and seeing the results is a powerful way to learn and understand the language. I encourage you to keep going, and to keep learning. You can do it! Good luck!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee