Hi iam trying to write a script, for a calculus competition (shrot) :

I wil have two competitors, both will play the game / competition until one leads by 2 points then the game is over.

Anyways it goes like this: In first round first competitor enters two factors / numbers say 5 and 2 in to a input field then the second competitor is prompted whit a input and needs to anwser whit the combined value of the two 5+2=7 if second competitor guesed the right value "7" he gets 1 point if not then he gets 0 points but its his turn then to enter the factors and first competitors task to anwser.

And where is the calculus in this?

Haha, no calculus.

Anyway...

score = 0 # Sets player score to 0
score_ = 0 # Sets player 2 score to 0

print """Welcome to the Calculus (?) Game! In this game, players \ntake turns entering integers (negative or postive) and\nfinding the sum. When you get a question correct,\nyou get a point. If one leads by five points at anytime\nin the game, they win, and the game\nends. Good luck!\n\nIf you get an error for typing a letter\nwhen you were supposed to enter a number,\nnot my fault. Have some common sense."""
player = raw_input("\nPlayer one, what is your name: ")
if player == '':
    player = "Player 1"
else:
    player = player
player_ = raw_input("Player two, what is your name: ")
if player_ == '':
    player_ = "Player 2"
else:
    player_ = player_
print "Let's begin! Hit RETURN to start!"
var = raw_input()
loop_var = 1 # Makes the game loop until a winner is decided
while loop_var == 1:
    factor = int(raw_input("\n%s, please enter your first factor: "%player))
    factor_ = int(raw_input("Now enter your second: "))
    correct = factor + factor_
    
    input = int(raw_input("%s, what is %s + %s: "%(player_,factor, factor_)))
    if input == correct:
        print "Good!"
        print "............................"
        score = score + 1
    else:
        print "Sorry, that's wrong."
        print "............................"
    score_check = score_ + 5 # Set so if player is leading by 5 points, he wins. To change to 2 points, change 5 to 2.
    if score_check == score:
        print "Player 1 wins the game!"
        break
    else:
        print """Scoreboard:

    %s: %s
    %s: %s
    """%(player,score,player_,score_)
    if score > score_:
        print "%s is in the lead!"%player
    elif score < score_:
        print "%s is leading the game!"%player_
    else:
        print "The players are currently tied!"
    print "............................"

    factor = int(raw_input("%s, please enter your first factor: "%player_))
    factor_ = int(raw_input("Now enter your second: "))
    correct = factor + factor_

    input = int(raw_input("\n%s, what is %s + %s: "%(player,factor, factor_)))
    if input == correct:
        print "Good!"
        print "............................"
        score_ = score_ + 1
    else:
        print "Sorry, that's wrong."
        print "............................"
    score_check = score + 5 # Set so if player 2 is leading by 5 points, he wins. To change to 2 points, change 5 to 2.
    if score_check == score_:
        print "%s wins the game!"%player_
        break
    else:
        print """Scoreboard:

    %s: %s
    %s: %s
    """%(player,score,player_,score_)
    if score > score_:
        print "%s is in the lead!"%player
    elif score < score_:
        print "%s is leading the game!"%player_
    else:
        print "The players are currently tied!"
    print "............................"
#Made by KrazyKitsune from Daniweb forums

Need more? I'll be happy to add.

To the godly Python coders that say that this code can be made simpler and more Pythonic: I know it can. But I'm a newb myself, don't blame me.

It was hard to concentrate but i did it another way found it to be quite simpler
then it actualy looked just needed to put my head to the task.

This game will go on until someone leads by 2 points.. I am more web development
oriented i learned 5 years programing in PHP / Ruby this sudden change to Python
was a baseball to face but whit some logic and clear thinking aplied its not all
that hard.

s1 = 0 #Player 1 Score
s2 = 0 #Player 2 Score

while (abs(s1 - s2)!= 2):
    x = input("Faktor: ")
    y = input("Faktor: ")
    z = input("Rezultat: ")


    if z == x * y:
        s2 = s2 + 1
        print "Trenutni rezultat : ", s1, " : ", s2

    a = input("Faktor: ")
    b = input("Faktor: ")
    c = input("Rezultat: ")

    if c == a * b:
        s1 = s1 + 1
        print "Trenutni rezultat : ", s1, " : ", s2

print
print "Koncni rezultat : ", s1, " : " ,s2

if s1 > s2:
    print "Bravo prvi ! Cvek Drugi"
else: s2 > s1
print "Bravo drugi ! Cvek Prvi"

Maybe you have some repeating code which could benefit from function definition?

Also I often find it clear for myself at least, to use conditional value instead of if, so last lines become

pair = 'prvi', 'Drugi'
print "Brovo %s! Cvek %s!" % (pair if s1 > s2 else  pair[::-1])

You can also use an indicator for wrong answers:

right_answers = True
while (abs(s1 - s2)!= 2):
    x = input("Faktor: ")
    y = input("Faktor: ")
    z = input("Rezultat: ")
 
 
    if z == x * y:
        s2 = s2 + 1
        print "Trenutni rezultat : ", s1, " : ", s2
    else:     ## assuming the above was the correct answer
        right_answers = False
#
#     finally
if right_answers:
    print "correct or whatever"
else:
    print "wrong"
# ----------------------------------------------------------------
#     with a function that can be called as many times as you want
def multiply_get():
    a = input("Faktor: ")
    b = input("Faktor: ")
    c = input("Rezultat: ")
 
    if c == a * b:
        return True

    return False

Great. I'm the only one in English now. ._.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.