i tried this in python 2.4? but it is not working

2019-09-22 06:18发布

Task 3 Determining the outcome of an encounter When there is an encounter between two characters the outcome is determined by the following process:

• The differences between the strength attributes for the two characters is calculated

• This difference is divided by 5 and then rounded down to create a ‘strength modifier’

• The process is repeated for the skill attribute to create a ‘skill modifier’

• Each player throws a 6 sided dice.

• If the scores on both dice are the same, no changes are made

• If the scores are not the same, the player with the highest score adds the ‘strength modifier’ to the strength value and the ‘skill modifier’ to the skill value for their character

• The player with the lower score on the dice subtracts these modifiers from the strength and skill values for their character

• If a skill value becomes negative, then it is stored as zero

• If a strength value becomes zero or negative, then the character dies.

The program should:

*• Allow the user to input the strength and skill for two characters.

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

enter code hereprint("you have chosen: "+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`

this is not working properly. It is not doing what it should. please help.

1条回答
Root(大扎)
2楼-- · 2019-09-22 06:52

random.randint is a function. I think you intended to use...

if(random.randint() < umar):

And alike in many lines of the code.

查看更多
登录 后发表回答