5 + 3 * 2n-2 ------------ 10 * p
if x % 2 == 1: if x**3 != 27: x = x + 49 else: x = x / 1.5 else: if x <= 10: x = x * 2 else: x = x - 2 print(x)
What does this code print if x == 3?
What does this code print if x == 12?
What does this code print if x == 4?
Another example: Baggins, Frodo as input would output 'Frodo' for first, 'Baggins' for last, and output 'Frodo Baggins' for name2.
>>> name = input("Enter name: last, first -\n example Smith, John--: ") Enter name: last, first - example Smith, John--: Jacobson, Mark >>> name 'Jacobson, Mark' >>> first = >>> first 'Mark' >>> last = >>> last 'Jacobson' >>> >>> name2 = >>> name2 'Mark Jacobson'
a_month = int( input('Enter the month: ') ) a_day = int( input('Enter the day : ') ) b_month = int( input('Enter the month: ') ) b_day = int( input('Enter the day : ') ) # fill in the blank
Step/phase #1: Step/phase #2: Step/phase #3:
x = input('Enter a string: ') y = 0 for ch in x: print(ch, end=' ') y += 1 if y % 4 == 0: print( x[0:y] )
What does this code print if the user enters 'PANTHERS'?
Note: Show what the output would look like too.
... or if n = 11 or n = 12, the output would be 36, since 1 + 3 + 5 + 7 + 9 + 11 = 36.
for i in range(10,100,5): print(i)
Write a while loop that does exactly the same thing as the for loop.
Enter the source : Ghostbusters Enter char to replace: s Enter char to insert : * Result: Gho*tbu*ter*
Write Python code that prints out the characters in string str, only with character old_ch replaced with character new_ch.
str = input('Enter the source : ') old_ch = input('Enter char to replace: ') new_ch = input('Enter char to insert : ') # fill in the blank
**** Another example: Enter the source : MISSISSIPPI Enter char to replace: I Enter char to insert : # print('\nResult:', result) Result: M#SS#SS#PP#
Enter an integer : 357 Enter an integer : 123456 Result: 357 digit sum is 15 Result: 123456 digit sum is 21
Write the Python code that obtains the sum of the digits in
number.
The first statement and the last statement
of the program are given for you.
number = input('Enter an integer : ') # fill in the blank print('\n', number, "digit sum is", digitSum)