python123第一周作業


1.使用turtle庫繪制一個紅色五角星圖形

import turtle

turtle.pensize(4)
turtle.pencolor("black")
turtle.fillcolor("red")

turtle.begin_fill()
for _ in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()

2.使用turtle庫繪制一個六角形

import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.pensize(1)
turtle.pencolor("red")
turtle.fillcolor("yellow")
turtle.fd(100)
turtle.seth(30)
turtle.pendown()
turtle.begin_fill()
turtle.fd(80)
turtle.seth(-90)
turtle.fd(80)
turtle.seth(150)
turtle.fd(80)
turtle.end_fill()
turtle.penup()
turtle.seth(30)
turtle.fd(80/3)
turtle.seth(90)
turtle.fd(80/3)
turtle.pendown()
turtle.begin_fill()
turtle.seth(-30)
turtle.fd(80)
turtle.seth(-150)
turtle.fd(80)
turtle.seth(90)
turtle.fd(80)
turtle.end_fill()

3.使用turtle庫繪制一個疊加等邊三角形

import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.pensize(1)
turtle.pencolor("red")
turtle.fillcolor("purple")
turtle.begin_fill()
turtle.seth(60)
turtle.pendown()
turtle.fd(50)
turtle.seth(-60)
turtle.fd(100)
turtle.seth(-180)
turtle.fd(100)
turtle.seth(60)
turtle.fd(50)
turtle.seth(0)
turtle.fd(50)
turtle.seth(-120)
turtle.fd(50)
turtle.seth(120)
turtle.fd(50)
turtle.end_fill()

4.分兩次從控制台接收用戶的兩個輸入:第一個內容為"人名",第二個內容為"心里話"。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

然后將這兩個輸入內容組成如下句型並輸出出來:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

      (人名),我想對你說,(心里話)

name=input()
heartword=input()
str1=name+',我想對你說,'+heartword
print(str1)

5.編寫一個程序,計算輸入數字N的0次方到5次方結果,並依次輸出這6個結果,輸出結果間用空格分隔。其中:N是一個整數或浮點數。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

print()函數可以同時輸出多個信息,采用如下方法可以使用空格對多個輸出結果進行分割:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬print(3.14, 1024, 2048)

n=eval(input())
for i in range(5):
print(pow(n,i),end=" ")
print(pow(n,5))

6.請使用Python語言輸出這個例子的中文版本,向世界發出第一聲問候吧!

print('世界,你好!')

7.用戶輸入兩個數M和N,其中N是整數,計算M和N的5種數學運算結果,並依次輸出,結果間用空格分隔。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬

5種數學運算分別是:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬M與N的和、M與N的乘積、M的N次冪、M除N的余數、M和N中較大的值

m=eval(input())
n=eval(input())
print(m+n,m*n,m**n,m%n,max(m,n))

8.模仿以下代碼,增加輸入部分,輸入自己的姓名,在屏幕上輸出“Hello,某某某同學!”(其中某某某用輸入的姓名替換)

n=input()
str='歡迎你,'+n+'同學!'
print(str)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM