-1

整数をRate、Remaining、Battery、kWhとして保存したいと思います。変数を格納し、コードの下部で方程式を実行できるように、これを修正するのを手伝ってください。

Rate = 0
while (Rate < 0.5) or (Rate > 2.0):
    Rate = int(raw_input("Enter Desired Rate of Charge: ")) #User will be prompted to enter the charge rate of the system
    if Rate < 0.5:
    #If the charge rate entered is less than 0.5 kWhs
        print "Charge Rate Too Low: Please consider revision" #Tells the user the rate is too low
    elif Rate > 2.0:
    #Also, if the charge rate entered is greater than 2.0 kWhs...
        print "Charge Rate Too High: Please consider revision" #Tells the user the rate is too high
    else:
    #Otherwise, for any number entered between the bounds of 0.5 and 2.0 kWhs...
        print '\n' #Page break for new conditions.

import random
Remaining = random.randint(0, 80) #Simulates remaining charge left over from the last use of the car. Defines the variable as "Remaining"

Battery = 0
while (Battery <=0) or (Battery >=80):
    Battery = int(raw_input("Enter Current Battery Life: "))
    #User will be prompted to enter the current battery level of the car. Defines that variable as "Battery"
    if Battery < 0:
    #If user input level is less than 0 kWh...
        print "Insufficient Entry (Too Low): Please consider revision" # Tells the user that the battery level entered is too low
    elif Battery > 80:
    #Also, if the user input level is greater than 80 kWh...
        print "Insufficient Entry (Too High): Please consider revision" # Tells the user that the battery level entered is too high
    kWh = 80 - Battery - Remaining
    print '\n' #Page break
    if kWh <=0:
        print "Battery Fully Charged!"
        print "There were " Remaining, " kWhs remaing from the last charge. 0 kWhs were charged."
        print "Buckle up! The rewards of the journey far outweigh the risk of leaving the garage!"
    else:
        print "Battery Fully Charged!"
        print "There were " Remaining, " kWhs remaing from the last charge. " kWh, "kWhs were added to recharge battery."
        print "Buckle up! The rewards of the journey far outweigh the risk of leaving the garage!"
4

2 に答える 2

1

交換

else:
    while Battery >=80:
        kWh=80-'Battery'-'Remaining'
        print kWh, "kWh"

プレーンで

kWh = 80 - Battery - Remaining
print(kWh, "kWh")
于 2012-12-06T06:26:50.060 に答える
0

問題の内容 (完全なトレースバック エラー) を教えていただければ、すぐに解決できたはずです。

print "There were " Remaining, " kWhs remaing from the last charge. 0 kWhs were charged."
print "There were " Remaining, " kWhs remaing from the last charge. " kWh, "kWhs were added to recharge battery."

問題です: ,beforeRemainingと beforeがありませんkWh

使用する

print "There were", Remaining, "kWhs remaing from the last charge. 0 kWhs were charged."
print "There were", Remaining, "kWhs remaing from the last charge. ", kWh, "kWhs were added to recharge battery."

そしてすべてがうまくいきます。

同様のエラーが発生した場合は、そこで何が起こっているかを確認し、実行されるまで修正してください。

ところで:コードを複製します。したほうがいい

print "Battery Fully Charged!"
print "There were", Remaining, "kWhs remaing from the last charge. ", # notice the ,
if kWh <=0:
    print "0 kWhs were charged."
else:
    print "kWh, "kWhs were added to recharge battery."
print "Buckle up! The rewards of the journey far outweigh the risk of leaving the garage!"

kWh(そして、の代わりに単に書く方が良いかどうかはわかりませんkWhs。単位の略語には複数形がありますか?そうは思いません...)

于 2012-12-06T07:09:25.300 に答える