我在python 2.4中试过这个?但它不能正常工作?

时间:2013-10-27 20:07:21

标签: python random python-2.4

任务3确定遭遇的结果当两个角色之间发生碰撞时,结果由以下过程确定:

•计算两个字符的强度属性之间的差异

•将此差值除以5,然后向下舍入以创建“强度修改器”

•对技能属性重复该过程以创建“技能修饰符”

•每位玩家掷出6面骰子。

•如果两个骰子上的得分相同,则不做任何更改

•如果得分不相同,得分最高的玩家会将“力量修正”添加到力量值,将“技能修饰符”添加到角色的技能值

•骰子得分较低的玩家从角色的力量和技能值中减去这些修饰符

•如果技能值变为负值,则将其存储为零

•如果强度值变为零或负值,则角色会死亡。

该计划应该:

*•允许用户输入两个角色的力量和技能。

import random
strength1 = input("Enter a value for strength")

enter code here print(“你选择了:”+ str(strength1))

skill1=input("Please enter a value of skill, and then press enter")
print("you have chosen: "+str (skill1))      

strength2 = input("Enter a value for strength")
print("you have chosen: "+str (strength2))

skill2=input("Please enter a value of skill, and then press enter")
print("you have chosen: "+str (skill2)) 


Strengthmodifiertoround=strength1
strength1= Strengthmodifiertoround

Skillmodifiertoround = skill1
skill1 = Skillmodifiertoround

Strengthmodifier = strength2
strength2 = Strengthmodifier

Skillmodifier = skill2
skill2 = Skillmodifier

print("character 1 strength is:"+str (strength1))
print("character 1 skill is:"+str (skill1))

print("character 2 strength is:"+str (strength2))
print("character 2 skill is:"+str (skill2))

if (strength1 < strength2):
    strengthmodifiertoround = strength2 - strength1;
    strengthmodifier = strengthmodifiertoround / 5;

if (strength2 < strength1):
    strengthmodifiertoround = strength1 - strength2;
    strengthmodifier = strengthmodifiertoround / 5;

if (skill1 < skill2):
    skillmodifiertoround = skill2 - skill1;
    skillmodifier = skillmodifiertoround / 5; 

if (skill2 < skill1):
    skillmodifiertoround = skill1 - skill2;
    skillmodifier = skillmodifiertoround / 5;

print("character 1 roll a dice")
print("You scored",random.randint(1,6))


print("character 2 roll a dice")
print("You scored",random.randint(1,6))
umar=random.randint(1,6)

if (random.randint < umar):
    char2st = strength2 + strengthmodifier
    char2sk = skill2 + skillmodifier
    print("").char2st
    print("character2strength"+str (char2st))
    print("character2skill"+str (char2sk))

else:
    char1st = strength1 - strengthmodifier
    char1sk = skill1 - skillmodifier
    print("character1strength"+str (char1st))
    print("character1skill"+str (char1sk))


if (umar < random.randint):
    ch2st = strength2 - strengthmodifier
    print("character2strength"+str (ch2st))
    ch2sk = skill2 - skillmodifier
    print("character2skill"+str (ch2sk))

else:
    ch1st = strength1 + strengthmodifier
    print("character1strength"+str (ch1st))
    ch1sk = skill1 + skillmodifier
    print("character1skill"+str (ch1sk)`enter code here`

这不能正常工作。它没有做它应该做的事情。 请帮忙。

1 个答案:

答案 0 :(得分:2)

random.randint是一个功能。我想你打算用......

if(random.randint() < umar):

在代码的许多行中都很相似。