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

  • Hello, This is what i wrote: def squareEach(nums): answer = [] for num in nums: answer.append(num*num)...

    Hello, This is what i wrote: def squareEach(nums): answer = [] for num in nums: answer.append(num*num) return answer def sumList(nums): answer = 0 for num in nums: answer += num return answer def toNumbers(nums): new_nums = [] for i in nums: new_nums.append(int(i)) return new_nums def main(): fileName = input("What file are the numbers in? ") sum = 0 with open(fileName, 'r') as infile: for line in infile: nums.append(line) print(nums) nums = toNumbers(line) print(nums) squares = squareEach(nums) print(nums) sum += sumList(squares)...

  • My module page is correct but I don't believe I am using the main() function properly....

    My module page is correct but I don't believe I am using the main() function properly. One of my .py files is supposed to contain my definitions, which is the module file. My second .py file is supposed to properly call a main function that does what my program asks it to: First name, last name, age, and respond based off of input. For some reason I am struggling with using the main() function so that my program works. Any...

  • 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...

  • 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():...

  • in python im trying to get this to print to the file i it created def...

    in python im trying to get this to print to the file i it created def calculateTotal(): filename = input("Enter a name for the file : ")#ask users for a name for file no_of_students = int(input("Enter the number of students in class : ")) data = [] with open(filename,"w+") as f: for index in range(no_of_students): grades = input("Enter Name of student plus grade :").split() # store the student data in array "data" data.append(grades) # store the total grades in "total"...

  • 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))

  • 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 #...

  • 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...

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