Python输入输出练习

  1. Hello World!
  2. 简单交互(交互式,文件式)
  3. 用户输入两个数字,计算并输出两个数字之和(尝试用一行代码实现)。
  4. 用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
1 a = float(input("a="))
2 b = float(input("b="))
3 c = float(input("c="))
4 p = (a+b+c)/2
5 area = (p*(p-a)*(p-b)*(p-c)) ** 0.5
6 print(‘三角形面积为 %0.2f‘ %area)

  1. 输入半径,计算圆的面积。
radius = float(input("输入半径:"))
2 area = 3.1415*radius*radius
3 print("{:.2f}".format(area))

  1. 画一组同切圆

    1 import turtle
    2 turtle.pensize(5)
    3 turtle.circle(10)
    4 turtle.circle(30)
    5 turtle.circle(30)
    6 turtle.circle(40)
    7 turtle.circle(100)

    显示如图:

  2. 画一个五角星

    import turtle
    turtle.forward(200)
    turtle.right(144)
    turtle.forward(200)
    turtle.right(144)
    turtle.forward(200)
    turtle.right(144)
    turtle.forward(200)
    turtle.right(144)
    turtle.forward(200)

    
    
  3. 画一个全黄色的五角星
 1 import turtle
 2 turtle.color("yellow")
 3 turtle.fillcolor("yellow")
 4 turtle.begin_fill()
 5 turtle.forward(200)
 6 turtle.right(144)
 7 turtle.forward(200)
 8 turtle.right(144)
 9 turtle.forward(200)
10 turtle.right(144)
11 turtle.forward(200)
12 turtle.right(144)
13 turtle.forward(200)
14 turtle.right(144)
15 turtle.end_fill()

时间: 2024-08-07 08:37:11

Python输入输出练习的相关文章

8、Python —— 输入输出

> 1.使用文件 # encoding: utf-8 # !/usr/bin/python # Filename : helloworld.py peom = '''如梦令 李清照 常记溪亭日暮, 沉醉不知归路. 兴尽晚回舟, 误入藕花深处. 争渡,争渡, 惊起一滩鸥鹭.''' # 模式可以为读模式('r').写模式('w')或追加模式('a') f = file('peom.txt', 'w') # open for 'w'riting f.write(peom) f.close() # 默认

Python 输入输出重定向

#基于Python2.7 #若是想Python做到和C++中freopen一样的输入输出重定向效果,即从文件输入输出,可以在程序中加入以下代码 1 import sys 2 sys.stdin=open('in.txt','r') 3 sys.stdout=open('out.txt','w')

Python输入输出

1        第一个Python [[email protected] python]# cat calc.py print(100+200+300) [[email protected] python]# python calc.py 600 [[email protected] python]# cat hello.py print('hello,world') [[email protected] python]# python hello.py hello,world [[email

学习1:python输入输出

1. 输出 >>> print "hello world" hello world >>> print 'hello world' hello world >>> print 'Hello','world' Hello world >>> print "I'm studing python" I'm studing python >>> print 'I am studing

python 输入输出,注释的使用

用EidtPlus新建一个py文件.代码如下(不能用notepad) #-*- coding:cp936 -*- print 'hello, python' print 'first 1', 'second 2' print '100 + 200 =', 100+200 #用户输入 """ 用户输入 """ name = raw_input() print '输入的数据:', name name = raw_input('please enter

python输入输出简记

python输入/输出1)输出方式: 1.表达式语句 2.print()函数 3.文件对象的write()(标准输出文件可以用sys.stdout引用)2)输出格式: 1.str.format():格式化输出值 a.括号及其里面的字符(称作格式化字段) 将会被 format()中的参数替换: eg:>>> print('{}先森: {}!'.format('yangrongkuan', '就读于华师')) #输出:yangrongkuan先森:就读于华师! b.在括号中的数字用于指向传入

Python输入输出练习,运算练习

Hello World! 简单交互(交互式,文件式)教材P19 用户输入两个数字,计算并输出两个数字之和: 用户输入三角形三边长度,并计算三角形的面积:(海伦公式) 输入半径,计算圆的面积. 画一组同切圆 画一个五角星 画一个全黄色的五角星 Hello World! 简单交互(交互式,文件式)教材P19 用户输入两个数字,计算并输出两个数字之和: 用户输入三角形三边长度,并计算三角形的面积:(海伦公式) 输入半径,计算圆的面积. 画一组同切圆 画一个五角星 画一个全黄色的五角星 1Hello W

python 输入输出

1 if __name__=='__main__': 2 # ff=input() 3 # print(type(ff))#<class 'str'> 4 # a=int(input()) 5 # a1=raw_input()#python3 舍弃,python2还用 6 line=sys.stdin.readline() 7 line1=line.strip('\n') 8 # line1 = sys.stdin.readline().strip('\n') 9 # line2 = inpu

Python输入输出练习,运算练习,turtle初步练习

print('Hello World!') name=input('输入姓名') print('%s同学,你好'%name) print('和=',int(input('数字a='))+int(input('数字b='))) 三角新面积a=input('三角形的边a=') b=input('三角形的边b=') c=input('三角形的边c=') p=(float(a)+float(b)+float(c))/2 s=(float(p)*(float(p)-float(a))*(float(p)-