Python语言程序设计基础(1)—— 程序设计基本方法

Everybody in this country should learn how to program a computer,because it teaches you how to think.

                     ——史蒂夫~乔布斯

 

圆的面积

import math
radius = 25
area = math.pi*radius*radius
print(area)
print("{:.2f}".format(area))

 

输入

name = input("输入人名:")
print("{}".format(name))
print("{}".format(name[0]))
print("{}".format(name[1:]))

 

斐波那契

a , b = 1,1
while a < 1000 :
    print(a,end=',')
    a, b = b,a+b
print("")

 

同心圆

import turtle
turtle.pensize(2)
turtle.circle(10)
turtle.circle(20)

 

日期与时间

from datetime import datetime
now = datetime.now()
print(now)
print(now.strftime("%x"))
print(now.strftime("%X"))

 

习题部分

字符串拼接
str1 = input()
str2 = input()

print("{} {}".format(str1,str2))

 

sum(n)
n=input()
sum=0
for i in range(int(n)+1):
    sum+=i
print(sum)

 

9*9
for i in range(1,10):
    for j in range(1,i+1):
        print("{}*{}={:2}".format(j,i,j*i),end=' ')
    print("")

 

1! + 2! + 3! + ... + n!
n = input()
sum = 0
tmp = 1
for i in range(1,int(n)+1):
    sum+=tmp
    tmp*=(i+1)
print(sum)

 

猴子吃桃
ans = 1
for i in range(5):
    ans = (ans + 1)*2
print(ans)

 

 
 

转载于:https://www.cnblogs.com/TreeDream/p/9780459.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值