python练习题 Day1

python练习题 Day1

practice1.

编写Python程序以特定格式打印以下字符串(参见输出)
:“Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are”
输出:
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are

print("Twinkle, twinkle, little star,"
      " \n\tHow I wonder what you are! "
      "\n\t\tUp above the world so high, "
      "\n\t\tLike a diamond in the sky. "
      "\nTwinkle, twinkle, little star, "
      "\n\tHow I wonder what you are")

practice 2

编写一个Python程序来获取你正在使用的Python版本

import sys
print(sys.version)

practice 3

编写一个Python程序来显示当前的日期和时间。

import datetime
now = datetime.datetime.now()
print("Current data and time is")
print(now.strftime("%Y-%m-%d %H:%M:%S"))

practice 4

编写一个Python程序,从用户那里接受一个圆的半径并计算面积。

import math
r = float(input("请输入圆半径:"))
pi = math.pi
print("半径为" + str(r) + "的圆面积为" + str(pi * r ** 2))

practice 5

编写一个Python程序,它接受用户的姓和名,并以相反的顺序打印它们,并在它们之间加一个空格。

first = input("请输入你的姓:")
second = input("请输入你的名:")
print(second, first)

practice 6

编写一个Python程序,从user接收一系列逗号分隔的数字,并生成一个包含这些数字的列表和元组。

a = input("请输入数据:")
l = a.split(",")  # 这里split是选择,为分隔符进行分割
t = tuple(l)
print("list:", l)
print("tuple", t)


practice 7

编写Python程序接受用户的文件名,并打印该文件名的扩展名。

FileName = input("请输入文件名:")
f = FileName.split(".")
print("该文件的拓展名为:" + f[-1])

practice 8

编写一个Python程序来显示下面列表中的第一个和最后一个颜色:
color_list = [“Red”,“Green”,“White” ,“Black”]

color_list = ["Red", "Green", "White", "Black"]
print(color_list[0], color_list[-1])

practice 9

编写一个Python程序来显示考试时间表。(从exam_st_date中提取日期)。
exam_st_date =(11,12,2014)
输出示例 : 考试开始时间为 : 11 / 12 / 2014

exam_st_date = (11, 12, 2014)
print("考试开始时间为: %i / %i / %i" % exam_st_date)

practice 10

编写一个Python程序,接受一个整数(n)并计算n+nn+nnn的值。

s = int(input("请输入n值:"))
t = s*10 + s
y = t*10 + s
print(s + t + y)

每天十题打卡。希望能坚持下去

你可能感兴趣的:(笔记,python)