Write a Python if statement that calls doWhat() if a and b is true or a and not c is true or e is equal to q.
Write an example of a Python for loop that uses a range.
Write an example of a Python for loop that iterates on the members of a container such as a list.
Show by code example in Python how to concatenate two strings and assign the result to a variable.
Write a Python if statement that calls doWhat() if a and b is true or a and not c is true or e is equal to q.
Answer:
--------
if (a and b) or (a and not c) or (e == q):
doWhat()
Write an example of a Python for loop that uses a range.
Answer:
--------
for i in range(10):
print(i)
Write an example of a Python for loop that iterates on the members of a container such as a list.
Answer:
--------
numbers = [3, 9, 2, 1, 7, 5]
for num in numbers:
print(num)
Show by code example in Python how to concatenate two strings and assign the result to a variable.
Answer:
--------
s1 = 'hello '
s2 = 'world'
result = s1 + s2 # concatenate two strings and store result in a string
print(result)
Write a Python if statement that calls doWhat() if a and b is true or a...
Write Python code examples of statements to remove the name at position 2 from the list in problem 32, and to remove one of the remaining names by referencing that name. Write Python code to declare a tuple named stuck that holds the three remaining names from famfri by referencing those names as elemens of famfri. Declare a Python set containing the names of the four seasons. What happens if you declare a set using a list that contains two...
USE Python 1. Assign value 555 to the variable x, write code to square the variable x and print out the result. 2. Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True" . 3. We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two numbers (the result should be 'Python3.0').
write a single python statement to create a tuple with two elements, the strings 'yap' and 'foo' and assign then to a variable called t.
Using Python latest version. 4. File Name: usernameListMe a. In this file, write the code to create a python list of strings that are 4 classes that are offered in the ICT program like "ict463" . b. Then create a list of 4 classes that are Gen-ED courses like "math121". c. Write the code to concatenate the lists into a third variable. d. Add a line of code to add one more Gen-ED course to the third - concatenated variable. e.Add...
Python code: 1. This question practices the use of a list method. Assign to the variable grades a list of 10 letter grades from among ‘A’, ‘B’, ‘C’, ‘D’, and ‘F’. For example: grades = [‘A’, ‘F’, ‘C’, ‘F’, ‘A’, ‘B’, ‘A’, ‘C’, ‘A’, ‘B’] Write a Python expression that creates a list named frequency, in which the elements are the number of times each of the letters A, B, C, D and F appear in grades. For example, for...
Hello can anyone help solve this please in Python the way it's
asked?
Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...
Write Python statements corresponding to the following: (a) assign to variable numYes the number of occurrences of 'Y' in list answers. (b) assign to variable numNo the number of occurrences of 'N' in list answers. (c) assign to variable percentYest the percentage of strings in answers that are 'Y'. (d) sort the list answers. (e) Assign to variable f the index of the first occurrence of 'Y' in sorted list answers.
(Write or type in answers, except for problem #15, which should be entered as a small program, tested, and submitted in Repl.it) 1. Write a Python statement to define a list named temps using the following elements, in order: 95, 100, 77, 54, 103, 82 2. a) What is the length of the list temps? b) What Python function can be used to obtain the length of the list? Use it in a statement to obtain the length of temps...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
1. Please write the following code in Python 3. Also please show all output(s) and share your code. Below is a for loop that works. Underneath the for loop, rewrite the problem so that it does the same thing, but using a while loop instead of a for loop. Assign the accumulated total in the while loop code to the variable sum2. Once complete, sum2 should equal sum1. sum1 = 0 lst = [65, 78, 21, 33] for x in...