Question

Write a Python if statement that calls doWhat() if a and b is true or a...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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)
Add a comment
Know the answer?
Add Answer to:
Write a Python if statement that calls doWhat() if a and b is true or a...
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
  • USE Python 1. Assign value 555 to the variable x, write code to square the variable...

    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').

  • Using Python latest version. 4. File Name:  usernameListMe a. In this file, write the code to create...

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

  • Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...

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

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

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

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

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

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • s1 = 'Practice How to Use String Object' Write a python statement that splits the string,...

    s1 = 'Practice How to Use String Object' Write a python statement that splits the string, creating the following list: ['Practice', 'How', 'to', 'Use', 'String', 'Object'] 2. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’: reply = input("Y or y to continue: ") if reply == "Y" and reply == "y":    print("Y --- <uppercase> has been selected. ") else:    print("y --- <lowercase> has been chosen. ") print("… continue...

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

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