1.
Line 1: no colon at the end of the statement and no comma between the arguments.
Fix: def modify (word, ch):
Line 2: Incorrect use of "==", instead it should be "="
Fix: word = word + ch
Line 3: return statement should be the last statement in the function.
Line 4: this statement should come before line 3.
The correct code:
def modify(word, ch):
word = word + ch
print('new word is', word)
return word
result = modify('course', 's')
2)
a) int -> 1
bool -> True
str -> "Hello"
float -> 3.14
b) str -> "Hello" + "world" evaluates to "HelloWorld"
bool -> (3 > 5) and (4 != 0) evaluates to False
list -> [1, 2, 3] + [4, 5] evaluates to [1, 2, 3, 4, 5]
c)
count == limit ----> True
count != limit ----> False
count <= limit or count >= limit ----> True
NOTE: As per HOMEWORKLIB POLICY I am allowed to answer specific number of questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word)...
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....
PYTHON PROBLEM Define a function generate_kv_strings( dictionary ) that creates and return a list where the element is a string representing a key-value pair in the format "key: value". Your solution must use a list comprehension. Hint: Remember that you need to convert each key and value into a str before concatenating them, in case they are of a different type. Example Usage: states = {'Florida': 'FL', 'Oregon': 'OR', 'California': 'CA', 'New York': 'NY', 'North Carolina': 'NC'} numbers = {'four':...
# Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sVal + str(tree.getRootVal()) sVal = sVal + printexp(tree.getRightChild())+')' return sVal #### Functions and classes to help with Homework 6 #### You should not make any changes to the functions and classes in this file, #### but you should understand what they do and how they work. import sys ### This function will be re-defined in hw6.py. However, it is needed for ExpTree, ###...
C++ Modify this program (or create your own) so that it performs the following tasks: 1. Insert the numbers into the list in sorted order (ascending). This will require you to keep the list sorted as you continue to insert new numbers. 2. When adding a new number, first check to see whether it is larger than the last number currently in the list. If it is, add it directly to the end of the list, i.e., do not traverse...
**TStack.py below** # CMPT 145: Linear ADTs # Defines the Stack ADT # # A stack (also called a pushdown or LIFO stack) is a compound # data structure in which the data values are ordered according # to the LIFO (last-in first-out) protocol. # # Implementation: # This implementation was designed to point out when ADT operations are # used incorrectly. def create(): """ Purpose creates an empty stack Return an empty stack """ return '__Stack__',list() def is_empty(stack): """...
Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...
C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...
This project is meant to give you experience writing linked lists and graphs. As such, you are not permitted to use arrays or any data structure library. You may, however, make use of code presented in class and posted to Blackboard. Objective Your goal for this project is to take a block of text, analyze it, and produce random sentences in the style of the original text. For example, your program, given Wizard of Oz, might produce: how quite lion...
A study followed 20 infants to find out when they speak their first word of English (in an English-speaking household). They found that the children were 13 months old on average when they spoke their first word; the data had a standard deviation of 4.93 months. What is the average age at which the population of children speak their first English word? First answer each of these questions: i) Does this call for a confidence interval or a hypothesis test?...