gpt4 book ai didi

Python用户输入和打印

转载 作者:太空宇宙 更新时间:2023-11-04 10:15:50 25 4
gpt4 key购买 nike

chargePerDay = 30.0
feeEachMile = 0.5
fuelPerGallon = 1.5

print("How many users are there?")
numberOfUsers = input()

for i in range(numberOfUsers):
print('For user ' + i)

print("Number of days")
numberOfDays = input()

print("Number of miles")
numberOfMiles = input()

totalRentalFee = (chargePerDay * float(numberOfDays)) + (feeEachMile * float(numberOfMiles))
print('Hi user ' + i + ' Your total rental fee is ' + str(totalRentalFee))

当我运行它时它正在打印对于范围内的我(用户数):TypeError: 'str' 对象不能解释为整数

这是怎么回事??请帮忙!

最佳答案

你输入的是一个字符串,你需要把它转换成一个整数:

numberOfUsers = int(input())
# ... rest of code

关于Python用户输入和打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35471427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com