Question

THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as...

THIS IS THE CODE I AM TRYING TO RUN

code

# def main():

      #Reading a as an integer

      a = int(input("Enter value for a: "))

      #reading b as an interger

      b = int(input("Enter value for b: "))

      #reading n as an integer

      n = int(input("Enter value for n: "))

      # displaying if a and b are congruent modulo n, this is True if a and b

      #both returns same remainder when divided by n

      if a % n == b % n:

             print(True)

      else:

        print(False)

      #displaying values of a mod n and b mod n

      print("a mod n:", a % n)

      print("b mod n:", b % n)

      #calling main()

      main()

I AM GETTING THE ERROR BELOW: PLEASE HELP:

y
^
SyntaxError: invalid syntax
>>> & C:/Users/dworl/AppData/Local/Programs/Python/Python37-32/python.exe c:/Users/dworl/Desktop/Assignment/arecongruent.py
File "<stdin>", line 1
& C:/Users/dworl/AppData/Local/Programs/Python/Python37-32/python.exe c:/Users/dworl/Desktop/Assignment/arecongruent.py
^
SyntaxError: invalid syntax
>>>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

There is a couple of errors in your code. On the first line, before def keyword, there is a ‘#’ symbol, which means that the line is commented out, that should be removed or else nothing will work. And secondly, at the end of your main() method definition, you attached the call to invoke main() the indentation is not correct, it should be placed with one less indentation level (should be on the same level as the def keyword in main).

Here is the fixed code for this problem. Go through it, and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

def main():
    #reading a as an integer
   
a = int(input("Enter value for a: "))
    # reading b as an integer
   
b = int(input("Enter value for b: "))
    # reading n as an integer
   
n = int(input("Enter value for n: "))
    # displaying if a and b are congruent modulo n, this is True if a and b
    #both returns same remainder when divided by n
   
if a % n == b % n:
        print(True)
    else:
        print(False)
    #displaying values of a mod n and b mod n
   
print("a mod n:", a % n)
    print("b mod n:", b % n)

#calling main()
main()

Add a comment
Know the answer?
Add Answer to:
THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...

    I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function

  • For my computer class I have to create a program that deals with making and searching...

    For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...

  • I am completing a rental car project in python. I am having syntax errors returned. currently...

    I am completing a rental car project in python. I am having syntax errors returned. currently on line 47 of my code "averageDayMiles = totalMiles/daysRented" my entire code is as follows: #input variable rentalCode = input("(B)udget , (D)aily , (W)eekly rental? \n") if(rentalCode == "B"): rentalPeriod = int(input("Number of hours rented?\n")) if(rentalCode == "D"): rentalPeriod = int(input("Number of days rented?\n")) if(rentalCode == "W"): rentalPeriod = int(input("Number of weeks rented?\n")) rentalPeriod = daysRented return rentalCode , rentalPeriod budget_charge = 40.00 daily_charge...

  • What is wrong with my python code. I am receiving this error: Traceback (most recent call...

    What is wrong with my python code. I am receiving this error: Traceback (most recent call last): File "C:/Users/owner/Documents/numberfive.py", line 7, in if age > 18: TypeError: unorderable types: str() > int() My code is age= input("Enter your age:") if age > 18: print("You can vote.") else: print("You can't vote.") if age > 64: print ("You're a Senior Citizen...you deserve two votes") endofprogram = input("Please hit enter to exit from this program:")

  • convert this python code to c++ code def sort(a,b): if a > b: return b,a else:...

    convert this python code to c++ code def sort(a,b): if a > b: return b,a else: return a,b def main(): set1 = input('Enter the first pair of integers: ') set2 = input('Enter the second pair of integers: ') set3 = input('Enter the third pair of integers: ') set1 = set1.split(',') set1_0 = int(set1[0]) set1_1 = int(set1[1]) set2 = set2.split(',') set2_0 = int(set2[0]) set2_1 = int(set2[1]) set3 = set3.split(',') set3_0 = int(set3[0]) set3_1 = int(set3[1])    print(sort(set1_0,set1_1)) print(sort(set2_0,set2_1)) print(sort(set3_0,set3_1))

  • THE ATTACHMENTS:( needed to solve the problem above) (1) My Morse Code Program: #03/22/2018 #Creating a...

    THE ATTACHMENTS:( needed to solve the problem above) (1) My Morse Code Program: #03/22/2018 #Creating a program that translates sentences in to morse code def main():    morsecode_dict={}    line=""   f1 = open("MorseCode.txt",'r');    content = f1.readlines()    for x in content: #print x x=x.split() my_dict[x[0]]=x[1] print (morsecode_dict)    val=raw_input("Enter a String value: ") val.upper() output=""    for i in val: print (i.upper()) if(i!=' '): output = output + morsecode_dict[i.upper()]+' ' else: output = output+'\n' print ("-----Morse Code of The...

  • For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

    For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...

  • use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main...

    use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...

  • def main(): n = int(input('Enter number of cookies: ')) r = n / 48 sugar =...

    def main(): n = int(input('Enter number of cookies: ')) r = n / 48 sugar = r * 1.5 butter = r flour = r * 2.75 print('You need ' + str(sugar) + ' cups of sugar, ' + str(butter) + ' cups of butter, and ' + str(flour) + ' cups of flour for ' + str(n) + ' cookies.') main() Please explain what each function in this program does? Python

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT