Posts Tagged ‘eclipse’

1:00
2008-07-04

python学习进行时1

   Posted by: clarezoe    in Python

最近在学python,在google code 上建了两个项目:dicthon,用 dict.cn 的 API 做一个简易的英汉辞典,Huahua 给写了一个,用起来很方便,项目主页上可下载。我想在他的基础上再改动一些,比较加上语音和生词库之类的;第二个是 tuvio,小提琴的调音器,可能要借鉴一起吉它的调音器。

想法有了,得想办法实施,由于是初学者,python的书籍都是介绍语法什么的怎么用,没有像 C 语言那样有系统的练习册之类的。于是找了一些以前学 C 时候做的习题,用相同的算法用 python来写,以达到学习和熟悉的目的。

另外介绍另外一个IDE编辑器 geany,比我之前介绍的 editra 还要好,可以直接编译各种格式的程序,还包括终端 xterm。只怪我 vim 一直用不好,eclipse 又太臃肿,geany 目前为止正和我意。

今天是第一个练习:

从键盘上输入两个整数,求出它们的和

#!/usr/bin/python
# Filename : sum.py
x = int(raw_input(”Please enter a integer for x : “))
y = int(raw_input(”Please enter a integer for y : “))
sum = x + y
print “The sum of x and y is “, sum
print “The sum of x and y is “, x+y #You can either declare a new variance or just sum them up.

输出:

Please enter a integer for x : 9
Please enter a integer for y : 78
The sum of x and y is  87
The sum of x and y is  87

从中学到了:

  1. 当然是怎么运行 python 脚本:开头第一句;文件格式;运行方式 python 文件名
  2. 如何从键盘获得数值 raw_input( “提示语” )
  3. python 语句原来是不用加 分号 的,一行就是一个语句,要是在同一行要以 分号 隔开。以前写 perl 和 C 养成习惯了,呵呵

Tags: , , , , , , , ,

收藏 & 分享

Powered by 17fav.com