Python program for soccer odds

121 Views Asked by At
match = input('Enter match? ')
odd1 = input("Enter tip for home: ")
if(not odd1.replace(".","").isnumeric()): 
    print("Sorry home tip is not numeric")
    exit(0)
if(float(odd1)<=1):
    print("Odd cannot be less than one")
    exit(0)
odd2 = input("Enter tip for draw: ")
if(not odd2.replace(".","").isnumeric()):
    print("Sorry draw tip is not numeric")
    exit(0)
if(float(odd2)<=1):
    print("Odd cannot be less than one")
    exit(0)
odd3 = input("Enter tip for away: ")
#isnumberic() is it number
if(not odd3.replace(".","").isnumeric()):
    print("Sorry your tip is not numeric")
    exit(0) 
if(float(odd3)<=1):
    print("Odd cannot be less than one")
    exit(0)

print("Thank you, your odd is: ")
print("Match: ", match)
print("Home: ", odd1)
print("Draw: ", odd2)
print("Away: ", odd3)

Generally replace(val1, val2) method changes old value with a new one which is second argument. Why in this code checks if number is float. If I type float number in odd1 without replace, I am getting the message Sorry home tip is not numeric?

1

There are 1 best solutions below

1
Mohamed Hamada On

odd1.replace(".","") means that change every dot in the string odd1 into to nothing (means delete it) generally .replace() is used to search about a char in a string and replace it with another for example

s = "Hello. world"

r = s.replace(".", ",")

print(r)

this code replace every dot in the string s with a comma

and then .isnumeric() tests if the value of odd1 after replacing is a number or not