Question

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 the accumulator variable? ________________

#1. b. What's its data type? _____________

#1. c What's the purpose of it?

#2. a What's the loop variable? _____________

#2. b What's its data type? ________________

#2. c What's the purpose of it?

#3 How many iterations does the for loop have? _________

#4 Write the line(s) of code where the accumulator "accumulates" something into it ________________

#5 What gets accumulated into the accumulator? Explain in English.

B) Modify the value of labs variable such that it has the 9th element, 'lab6old'. Run the program again.

       #1. What do you get? Copy and paste the output from Scratchpad in here.

      #2. Explain the result.

labs = ['lab1a', 'lab1b', 'lab2', 'lab3', 'lab4a', 'lab4b', 'lab4c', 'lab5']

graded = ''

tutor_code = ''

for lab in labs:

    lab_num = int(lab[3])

    tutor_code = lab[3]

    if len(lab) == 5:

        tutor_code = tutor_code + lab[4]

        graded = graded + lab + ' assigned to ' + tutor_code + '\n'

    elif len(lab) < 5:

        graded = graded + lab + ' not assigned\n'

print(graded)

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

#please ask 1 question at a time. I have done the 1st one

def fun(num,letter):#syntax error, function definition is ended by :, arguments are to be separated by a comma
num = 7 + num#symantic error, we need to assign and not compare, which does nothing here
return str(num) + letter #run time error, we cant subtract a number from character,
#we can append it however to string representation

result = fun(5, 'x')#run time error, x should be a pre defined variable, or should be passed as string

def fun(num, letter): #syntax error, function definition is ended by :, arguments are to be separated by a comma num = 7 + nu

Add a comment
Know the answer?
Add Answer to:
1. Questions Python Code: For each line of code, write the type of error (syntax, semantics,...
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
  • Accumulation Pattern Problem 2 Consider the code below. 1 2 3 4 5 6 7 8...

    Accumulation Pattern Problem 2 Consider the code below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 labs = ['lab1', 'lab2', 'lab3', 'lab4', 'lab5', 'lab6', 'lab7', 'lab8', 'lab9'] graded = '' for lab in labs:     lab_num = int(lab[3])     if lab_num < 4:         graded = graded + lab + ' is simple\n'     elif lab_num < 7:         graded = graded + lab + ' is ok\n'     else:         graded = graded + lab + ' is complex\n'         ...

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • 1. Please write the following code in Python 3. Also, please write code and not psedo-code....

    1. Please write the following code in Python 3. Also, please write code and not psedo-code. 2. Please also share your code and show all outputs. Write code that uses the string stored in org and creates an acronym which is assigned to the variable acro. Only the first letter of each word should be used, each letter in the acronym should be a capital letter, and there should be nothing to separate the letters of the acronym. Words that...

  • Can someone help me with this Python code Summary In this lab, you work with the...

    Can someone help me with this Python code Summary In this lab, you work with the same Python program you worked with in Labs 5-1 and 5-3. As in those earlier labs, the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. However, in this lab you should accomplish this using a while loop with a break statement. Instructions Make sure that the file NewestMultiply.py is selected and open. Write...

  • Part 1: Using Idle Write a Python Script that Does the Following 1. At the top...

    Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...

  • Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats...

    Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats a group of statements in a program? a. loop b. switch c. main() function d. compiler 2. In the expression number++,the ++operator is in what mode? a. Prefix b. Pretest c. Postfix d. Posttest 3.This is a variable that controls the number of iterations performed by a loop. a. Loop control variable b. Accumulator c. Iteration register variable d. Repetition meter 4. The do-whileloop...

  • python rephactor 1. Write code that prints the square root of the value in the variable...

    python rephactor 1. Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported. 2. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal.

  • Write a piece of Python code that meets the following requirements: Write a loop structure such...

    Write a piece of Python code that meets the following requirements: Write a loop structure such that: The range of control values is from 0 up to, but not including 11. The control variable is incremented by 1 for each iteration of the loop. For each iteration of the loop: Evaluate the control value When the control variable is equal to 1, 2, 3, 5, or 7, output a line of text that reads: "x is a prime number" where...

  • CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first...

    CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first cout statement, and press Run to observe the error message. Fix the error, and run again. Repeat for the second, then third, cout statement cout << "Num: "<< songnum << endl; cout << int songNum << endl; cout << songNum " songs" << endl; Note: These activities may test code with different test values. This activity will perform two tests: the first with songNum-5,...

  • In python Please type the code Question 4: Write a program that reads an English word...

    In python Please type the code Question 4: Write a program that reads an English word from the user, and prints how many vowels and how many consonants it contains. Note: You may assume the letter Y is not a vowel. Sample output (2 different executions) Enter a word: test test has 1 vowels and 3 consonants Enter a word: Apple Apple has 2 vowels and 3 consonants.

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