Home > Blockchain >  Beginner python in the classroom
Beginner python in the classroom

Time:01-16

I'm new to python and I'm trying to do my labs for class and this one keeps giving me a syntax error. Please help out if possible.

import random
name = input("Please enter your name")
print(name)
integ = int(input(name   ","     " please enter an integer: "))
print(integ)
integ2 = int(input(name   ","   " please enter another integer: "))
print(integ2)
divis = (integ % integ2)
print(divis)
if divis == 0:
    print(str(integ)   " is divisible by "   (str(integ2))
else:
    print(str(integ)   " is NOT divisible by "   (str(integ2))```

CodePudding user response:

Your brackets are not balanced.

import random
name = input("Please enter your name")
print(name)
integ = int(input(name   ","     " please enter an integer: "))
print(integ)
integ2 = int(input(name   ","   " please enter another integer: "))
print(integ2)
divis = (integ % integ2)
print(divis)
if divis == 0:
    print(str(integ)   " is divisible by "   (str(integ2)))
else:
    print(str(integ)   " is NOT divisible by "   (str(integ2)))
 

CodePudding user response:

Your last 2 print statements are missing a closing ')'

import random
name = input("Please enter your name")
print(name)
integ = int(input(name   ","     " please enter an integer: "))
print(integ)
integ2 = int(input(name   ","   " please enter another integer: "))
print(integ2)
divis = (integ % integ2)
print(divis)
if divis == 0:
    print(str(integ)   " is divisible by "   (str(integ2)))
else:
    print(str(integ)   " is NOT divisible by "   (str(integ2)))

CodePudding user response:

You have forgotten to close the brackets. It should be like this:

import random
name = input("Please enter your name")
print(name)
integ = int(input(name   ","     " please enter an integer: "))
print(integ)
integ2 = int(input(name   ","   " please enter another integer: "))
print(integ2)
divis = (integ % integ2)
print(divis)
if divis == 0:
    print(str(integ)   " is divisible by "   (str(integ2)))
else:
    print(str(integ)   " is NOT divisible by "   (str(integ2)))
  •  Tags:  
  • Related