- 1、Python的幾個編程作業..求教TAT剛開始學….
- 2、Python作業題求解
- 3、Python作業題目
- 4、學計算機的同學幫看一個python入門的作業?
作業要自己做
#!/usr/bin/env python
print ”’I have 3 kinds of fruit:
apple: $1.29/lb
grage: $2.29/lb
orange: $1.5/lb”’
choice = raw_input(‘Which one do you want? ‘)
if choice == ‘grape’:
weight = float(raw_input(‘Ok, grape. How many pounds do you want? ‘))
print ‘the cost is’, round(weight*2.29,2)
elif choice == ‘apple’:
weight = float(raw_input(‘Ok, apple. How many pounds do you want? ‘))
print ‘the cost is’, round(weight*1.29,2)
elif choice == ‘orange’:
weight = float(raw_input(‘Ok, orange. How many pounds do you want? ‘))
print ‘the cost is’, round(weight*1.5,2)
else:
print ‘Sorry, we don\’t have that.’
#!/usr/bin/env python
def smallest(x,y,z):
temp = y if yz else z
return x if xtemp else temp
a = float(raw_input(‘Enter the 1st number: ‘))
b = float(raw_input(‘Enter the 2nd number: ‘))
c = float(raw_input(‘Enter the 3rd number: ‘))
print smallest(a,b,c),’is the smallest.’
#!/usr/bin/env python
left = int(raw_input(‘Enter the beginning integer: ‘))
right = int(raw_input(‘Enter the ending integer: ‘))
print (“All the integers between %d and %d that are divisible by both 3 and 7 are:” %(left,right))
for i in range(left,right+1):
if i%21==0:
print i,
Print = input(“請輸入需要強調的話:”)
Print = Print + “!”
number = int(input(“請輸入要重複的次數:”))
print(Print * number)
你好的!
我給你做一下第17 題:別的問題需要答案的話,挨個提問,否則沒人一下給你回答那麼多的問題
import math
def is_prime(n): # 簡化問題,先利用函數判斷是否為質數
if n == 1: # =是賦值,==才是判斷,切記切記
return False
for i in range(2, int(math.sqrt(n))+1): # 質數判斷條件,注意+1
if n % i == 0:
return False
return True
primes = []
name = int(input())
if is_prime(i) is True: # bool值用is判斷
print(‘the input number is prime number;’)
else:
print(‘the input number is not a prime number;’)
編寫程序,從鍵盤上輸入三個數字,用輸入的第一個數字除以第二個數字,得到的結果和第三個數字相加,在這個過程中注意要捕獲異常,根據錯誤類型去進行異常處理,如果沒有觸發異常的話,要輸出最後的計算結果,程序的最後要輸出提示語:程序執行結束。
原創文章,作者:HAFRR,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/126339.html