# list, set, tuple goods = [] prices = [] while True: good = input("请输入想购买的商品:") if good.lower() == "q": break price =float(input("请输入价格:" )) goods.append(good) prices.append(price) # print("商品", goods) # print("价格", prices) # # for index,good in enumerate(goods): # print("索引", index) # print("商品名称", good) # # for index, price in enumerate(prices): # print("价格", price) for index, good in enumerate(goods): print(f"第 {index + 1} 个商品是 {good},价格是 {prices[index]:.2f}") total = sum(prices) print(f"总价格是: {total} 元")
@s2097playКүн бұрын
1:15:30 字串方法,重複很多次字母大小寫方法是要讓我們新手加強的嗎?
@s2097playКүн бұрын
1:10:36 邏輯運算子 沒有看到not的範例
@王木匠-w8pКүн бұрын
fruits = ["apple","orange","banana","cocnut"] # print(fruits[0]) # for f in fruits: # print(f,end=" ") # fruits.append("apple") # print(fruits) # fruits.remove("orange") # print(fruits) # print(fruits.index("banana")) # fruits.append("banana") # fruits.append("banana") # fruits.append("banana") # print(fruits) # print(fruits.count("banana")) # fruits.reverse() # print(fruits) # set # fruits_set = {"apple","orange","banana","coconut"} # for f_s in fruits_set: # print(f_s, end=" ") # print() # if "apple" in fruits_set: # print("we have an apple now") # else: # print("we don't have apple") # # if "watermelon" in fruits_set: # print("we have an watermelon now") # else: # print("we don't have watermelon") # tuple fruits_tuple = ("apple","orange","banana","coconut") # fr = fruits_tuple.count("apple") # print(fr) location = fruits_tuple.index("orange") print(location)
@王木匠-w8pКүн бұрын
# for x in range(1,10): # print(x, end=" ") # for y in range(5): # for x in range(1,10): # print(x,end=" ") # print() # rows = int(input("请输入行数:")) # cols = int(input("请输入列数:")) # symbol = input("请输入符号:") # for i in range(rows): # for j in range(cols): # print(symbol,end=" ") # print() import time my_time = int(input("请输入秒数:")) for x in range(my_time,0,-1): seconds = x % 60 minutes = x //60 % 60 print(f"{minutes:02}:{seconds:02}") time.sleep(1) print("时间到了。")
@王木匠-w8pКүн бұрын
# for x in range(1,10): # print(x, end=" ") # for y in range(5): # for x in range(1,10): # print(x,end=" ") # print() rows = int(input("请输入行数:")) cols = int(input("请输入列数:")) symbol = input("请输入符号:") for i in range(rows): for j in range(cols): print(symbol,end=" ") print()
# # name = input("please enter yout name:") # # if name == "": # # print('你没有输入名字。') # # else: # # print(f'欢迎您, {name}') # # name = input('please enter your name:') # while name != 'a': # print(input('please enter your name:')) # # print(f'welcome,{name}') num = int(input('please enter your number:')) while num < 0 or num > 9: print(f'您输入的数字{num}无效') num = int(input('please enter your number:')) print(f'您输入的数字是 {num}')
@王木匠-w8p2 күн бұрын
price_1 = 32.22121 price_2 = -22 price_3 = 12.33 # print(f'price one is{price_1} ' # f'price two is{price_2} ' # f'price three is{price_3}') # print(f'price one is{price_1:.2f} ' # f'price two is{price_2:.2f} ' # f'price three is{price_3:.2f}') # print(f'price one is{price_1:+.2f} ' # f'price two is{price_2:+.2f} ' # f'price three is{price_3:+.2f}') print(f'price one is{price_1:10.2f} ' f'price two is{price_2:10.2f} ' f'price three is{price_3:10.2f}') print(f'price one is{price_1:<10.2f} ' f'price two is{price_2:<10.2f} ' f'price three is{price_3:<10.2f}') print(f'price one is{price_1:>10.2f} ' f'price two is{price_2:>10.2f} ' f'price three is{price_3:>10.2f}') print(f'price one is{price_1:^10.2f} ' f'price two is{price_2:^10.2f} ' f'price three is{price_3:^10.2f}') print(f'price one is{price_1:>+.2f} ' f'price two is{price_2:>+.2f} ' f'price thr is{price_3:>+.2f}')
@王木匠-w8p2 күн бұрын
credit_number = '1234-4124-412-442141' firt_char = credit_number[0] print('第一位数字',firt_char) second_char = credit_number[1] print('第二个数字',second_char) first_fouth =credit_number[0:4] print('from the first to the fouth',first_fouth) last_one =credit_number[-1] print('the lasr number',last_one) second_to_last =credit_number[-2] print('the second to last number is',second_to_last)
@王木匠-w8p2 күн бұрын
# # help(str) # # user name # name = "novel reader" # lenth = len(name) # print("your name has",lenth,"characters in total") # # # 找到第一个空格 # space_pos = name.find(" ") # print("第一个空格出现在",space_pos,"个字元") # # name_capitalized = name.capitalize() # print("您的全名:",name_capitalized) # # name_upper = name.upper() # print("您的全名是:",name_upper) # # name_lower = name.lower() # print("您的全名是:",name_lower) # # # count # phone_number = input("please enter yout phone number:") # dash_count = phone_number.count('-') # print("your phone has",dash_count,"-") # # phone_number = phone_number.replace('-',' ') # print("your phone number is:",phone_number) username = input('please enter your username:') if len(username) > 12: print('the longest username character cannot exceed 12 characters') elif ' ' in username: print('spaces cannot be used in usernames') elif not username.isalpha(): print('characters other than roman letters cannot be used in usernames') else: print('welcome',username)
@王木匠-w8p2 күн бұрын
temp = int(input("please enter current temperature")) # if temp > 0 and temp < 30: # print("comfortable temperature") # else: # print("hash temperature") if temp <= 0 or temp >= 30: print("hash temperature") else: print("comfortable temperature")
@yenju11062 күн бұрын
已經從Perplexity找到答案了 修改如下即可 while player not in options: player= input("input error, please key in paper,scissors, rock").lower( )
@CodeShibaКүн бұрын
問 ChatGPT 回答的比較詳細,比較有學習的效果。
@yenju11062 күн бұрын
您好 是否有高人可以幫忙說明,謝謝 import random player = None computer = None running = True options = ("paper", "scissors", "rock") while running : player = input("Please key in paper, scissors, rock") while player not in options: input("Please key in paper,scissors, rock") computer = random.choice(options) print(f"player: {player}, computer:{computer}") if player == computer: print("draw") elif player == "scissors" and computer == "paper": print("player won") elif player == "rock" and computer == "scissors": print("player won") elif player == "paper" and computer == "rock": print("player won") else: print("computer won") play_again = input("play again? y/n").lower() if not play_again == "y": running = False print("Thank you for playing the game") ------------------------------------------------------------------- 問題如下 while player not in options: input("Please key in paper, scissors, rock") 我發現如果我故意一開始打錯 程式會一直重複而跳不出來 例如 我故意打stone 結果如下 Please key in paper, scissors, rock stone Please key in paper,scissors, rock paper Please key in paper,scissors, rock scissors Please key in paper,scissors, rock rock Please key in paper,scissors, rock
@王木匠-w8p2 күн бұрын
unit = input("please enter the temperature unit(摄氏C,华氏F):") temperature = float(input('what is the temperature today?')) if unit == 'C': temperature = round(9 * temperature / 5 + 32) print(f'the current temperature is {temperature}度F') elif unit == 'F': temperature = round((temperature - 32) * 5 / 9) print(f'the current temperature is {temperature}度C') else: print("what the fuck?")
@王木匠-w8p2 күн бұрын
weight = float(input('please enter your weight:')) unit = input("is your weight in kilograms or pounds?(kg/lb):").upper() if unit == 'KG': weight *= 2.2 new_unit = '磅' elif unit == 'LB': weight /= 2.2 new_unit = '公斤' else: print('incorrect units') exit() print(f'your weight is {round(weight)} {new_unit}')
@王木匠-w8p2 күн бұрын
operator = input('请输入运算符号(加法:+,减法:-,乘法:*,除法:/):') num1 = float(input('请输入数字一:')) num2 = float(input('please enter the second number:')) if operator == '+': result = num1 + num2 elif operator == '-': result = num1 - num2 elif operator == '*': result = num1 * num2 elif operator == '/': result = num1 / num2 else: print("invalid operator symbol") print(f"the result of the operation is{result}")
@王木匠-w8p2 күн бұрын
# # for_sale = True # # if for_sale: # # print("此项目正在出售") # # else: # # print("此项目未出售") # age = int(input("请输入年龄")) # if age >= 18: # print("可以注册") # else: # print("你可以付费注册") age = int(input("请输入您的年龄")) if age<= 0: print("请慢慢投胎") elif age>= 100: print("恭喜您修成正果") else: print("赶紧去上班")
@王木匠-w8p2 күн бұрын
# # apples = 3 # # apples = apples + 1 # # print(apples) # # apples += 1 # # print(apples) # # apples -= 3 # # print(apples) # # apples *=100 # # print(apples) # # apples /= 20 # # print(apples) # print(100 % 3) # print(pow(2,3,3)) # x = 12 # y = 221 # z = 128819 # print(max(x,y,z)) # print(min(x,y,z)) # a = -3.2199 # print(round(a)) # print("绝对值:",abs(a)) # import math # # # x=4.3 # # print(round(x)) # # print(math.ceil(x)) # # print(math.floor(x)) # radius = float(input("请输入圆的半径:")) # c = 2 * math.pi * radius # print(f"圆的周长为{round(c,2)}") import math radius = float(input("请输入圆的半径:")) area = math.pi * pow(radius,2) print(f"圆的面积为:{round(area,2)}")
@王木匠-w8p2 күн бұрын
apples = 3 apples = apples + 1 print(apples) apples += 1 print(apples) apples -= 3 print(apples) apples *=100 print(apples) apples /= 20 print(apples)
@horusyang3 күн бұрын
# Python內建中的數學 # 加減乘除 x = 4 x = x+2 x += 2 x = x-2 x -= 2 x = x*4 x *= 4 x = x/4 x /= 4 # 指數(平方、三次方) 純手工公式 x =x ** 2 x **= 2 print(x) # 模數 mod(餘數) % # 13 mod 5 等於 2 餘 3 print(13 % 5) # 14 mod 5 等於 2 餘 4 print(14 % 5) # 15 mod 5 等於 3 餘 0 print(15 % 5) # 次方另一種呈現方式pow y = 2 print(pow(y,5)) # 最大值Max和最小值Min a = 15 b =2 c =31 print(max(a,b,c)) print(min(a,b,c)) # 四捨五入計算round a1 = 3.5484123 print(round(a1)) print(round(a1,1)) print(round(a1,2)) print(round(a1,3)) # 絕對值abs a2 = -31.235 print(abs(a2)) print(abs(round(a2,2))) # python math模組數學函數 --------------------------------------------------------- # python math模組數學函數 import math # 四捨五入、無條件進位(要math)celi、無條件捨去(要math)floor x = 31.256 print(round(x,2)) print(math.ceil(x)) print(math.floor(x)) # 圓周率𝝿 math.pi print(math.pi) # 圓周長 2𝝿R # 圓面積 𝝿R^2 # 圓柱表面積 2*𝝿R^2+2𝝿R*L # 圓柱體積 𝝿R^2*L r = input("請輸入圓半徑:") r = float(r) L = input("請輸入圓柱高:") L = float(L) circle_length = 2*math.pi*r circle_area = math.pi*pow(r,2) circle_surfacearea = 2*circle_area + circle_length*L circle_volume = circle_length*circle_area print(round(circle_area,2),round(circle_area,2),round(circle_surfacearea,2),round(circle_volume,2)) 感謝老師