Question

Describe what is wrong with the syntax of each the following blocks of code, and show...

Describe what is wrong with the syntax of each the following blocks of code, and show how to fix it.

while answer != 'q':
    answer = input('Word? ')
    print(len(answer))
0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer variable must be declared be fore usinq it in while loop

answer = ''
while answer != 'q':
    answer = input('Word? ')
    print(len(answer))
Add a comment
Know the answer?
Add Answer to:
Describe what is wrong with the syntax of each the following blocks of code, and show...
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
  • 2 of these blocks of code will produce an error if run. Find each statement with an error in it, ...

    2 of these blocks of code will produce an error if run. Find each statement with an error in it, describe the error and what behavior it will produce, and describe generally how you would fix it. print ("block 1" strl-"INST 126 is my first Python course" print (strl[-6:len Thu, Apr 11, 2019 9:38 PM it 6 characters of the string list1 = str1 . split() # split into words print (list 1 [len (list 1))) # get last word...

  • Code is wrong: python parsing warm up. while(True): inp_str = input('Enter input string: ') if (inp_str...

    Code is wrong: python parsing warm up. while(True): inp_str = input('Enter input string: ') if (inp_str == 'q'): break; while inp_str.find(",")==-1: print('Error: No comma in string. ') inp_str=input('Enter input string: ')       s=inp_str.split(",") print('First word:'+ s[0].strip()) print('Second word:'+ s[1].strip()) print('\n') This is my code for a problem but the output is wrong and I dont know how to fix it (the top is the output im getting the bottom is what i am supposed to get) Enter input string:...

  • 1. Questions Python Code: For each line of code, write the type of error (syntax, semantics,...

    1. Questions Python Code: For each line of code, write the type of error (syntax, semantics, runt-time), cause of the error, and your fix. (1) def fun(num letter) (2) num == 7 + num (3) return 'num' - letter (4) result = fun(5, x) 2. Question Python Code: Run the code below to check the outputs of the print() call on lines 12. And : A) Analyze the application of the accumulation pattern and answer the following questions: #1. a....

  • What is wrong with the following code? How would you fix it? (Assume all the appropriate...

    What is wrong with the following code? How would you fix it? (Assume all the appropriate import statements) /* print every other element in a linkedlist */ LinkedList<String> exampleLL = new LinkedList<String>(); exampleLL.add("Today"); exampleLL.add("is"); exampleLL.add("a"); exampleLL.add("sunny"); exampleLL.add("day"); exampleLL.add("outside"); ​​​​​​​exampleLL.add("I"); ​​​​​​​exampleLL.add("Like"); ​​​​​​​exampleLL.add("summer"); ​​​​​​​exampleLL.add("and"); ​​​​​​​exampleLL.add("the"); ​​​​​​​exampleLL.add("sunshine"); ​​​​​​​exampleLL.add("it"); ​​​​​​​exampleLL.add("brings"); ​​​​​​​exampleLL.add("too;"); /* etc etc etc */ ListIterator iter = exampleLL.ListIterator(); System.out.println("Every other word of the speach:") while (iter.hasNext()) { System.out.println(iter.next().next()); }

  • Python Problem Hello i am trying to finish this code it does not save guesses or...

    Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...

  • Please use Python3. Thanks Find and fix the errors (syntax or logic) in the following code...

    Please use Python3. Thanks Find and fix the errors (syntax or logic) in the following code snippet: # this function creates a 2D list using the height, width, and symbol. It does # not contain any shallow copies of rows def createList(height, width, symbol): board = [] for i in range(len(height)): row = [] for j in range(width): row.append(symbol) board.append(row) def main(): # creates 5 rows of 5 @s myList = createList(5,"@") print(board) main()

  • 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

  • What is wrong with the following code? This piece of code incorrectly attempts to remove all...

    What is wrong with the following code? This piece of code incorrectly attempts to remove all even values from a stack integers. How would you fix it? You will need to write a class with the main(String[] args) {….} method to test the following piece of code, find the problem, and fix it.                while (!s1.isEmpty()){                               int n = s1.pop();                               if (n % 2 != 0) {                                 s1.push(n); // if odd put it back.                               }                }

  • What is the below code attempting to do (continuing from previous part)? What is wrong with this ...

    C++ We were unable to transcribe this imageWhat is the below code attempting to do (continuing from previous part)? What is wrong with this approach? How would you fix this? n- head; while(n)\ if(n->data == 2) { delete n; n = n-> next; else\ n = n->next; What is the below code attempting to do (continuing from previous part)? What is wrong with this approach? How would you fix this? n- head; while(n)\ if(n->data == 2) { delete n; n...

  • python programming: Can you please add comments to describe in detail what the following code does:...

    python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try:    f = open("shopping2.txt","r")    for line in f:        sl.append(line.strip())    f.close() except:    pass def mainScreen():    os.system('cls') # for linux 'clear'    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print(" SHOPPING LIST ")    print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")    print("\n\nYour list contains",len(sl),"items.\n")    print("Please choose from the following options:\n")    print("(a)dd to the list")    print("(d)elete from the list")    print("(v)iew 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
ADVERTISEMENT