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

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

大家好,又见面了,我是你们的朋友全栈君。

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://javaforall.net/156004.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号