带加号的健康吧/已关闭

时间:2019-09-10 03:02:54

标签: python-3.x

我正在编写一个代码,其中用户的健康状况显示为加号,但我需要该框为40-标记长。加号不能超出它们的范围。 Hp_Cur是加号的数量。

Hp_Cur = int(input("Enter current health: "))

Hp_Max = int(input("Enter Max health: "))


print ("/", "-"*40, "\\")

print ("|", "+"*Hp_Cur, "|")

print ("\\", "-"*40, "/")

1 个答案:

答案 0 :(得分:-1)

您好,KingVarric,我想您想要该程序:

-确保加号不大于方框

-将最后一个中间的“ |”和盒子一样

#this is my interpretation of your problem
Hp_Cur = int(input("Enter current health: "))

Hp_Max = int(input("Enter Max health: "))
# you can input 40 to make it 40 marks long

if Hp_Cur > Hp_Max:
#do test and limit plus signs
    print("Your Current Hp is bigger than your Max Hp")
else:
    print ("/", "-"*Hp_Max, "\\")
    print ("|", "+"*Hp_Cur, " "*(Hp_Max-Hp_Cur) + "|")#" "*(40-Hp_Cur) adds the necessary spaces
    print ("\\", "-"*Hp_Max, "/")