Download Mastering Loops - TeachYourselfPython

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Elementary mathematics wikipedia , lookup

Transcript
Challenge yourself in Python
Selection
Functions
Loops
Strings
INT E RMEDIATE L E V EL C H A LLENGES
Level 2
Note: Feel free to use the internet for research while completing these challenges
Lists
Task 1:
Write a Python program to
find the median of three
values.
Expected Output:
Input first number: 15
Input second number: 26
Input third number: 29
The median is 26.0
Paste or screenshot your code here.
Design / Flow chart
Task 2:
• Write a Python program to
reverse a string.
• Sample String : "1234abcd"
Expected Output :
"dcba4321"
• This task is harder than it
looks and you definitely
want to try and design it
before attempting to code it!
Answers and Screenshot or paste your solution code here
Design / Flow chart
Task 3:
• Write a Python function to
multiply all the numbers in a
list.
• Sample List : (8, 2, 3, -1, 7)
Expected Output : -336
Screenshot or paste your solution code here
Design / Flow chart
Task 4:
• Write a Python function to
sum all the numbers in a
list.
• Sample List : (8, 2, 3, 0, 7)
Expected Output : 20
Screenshot or paste your solution code here
Design / Flow chart
Task 5:
Write a Python function that checks
whether a passed string is
palindrome or not.
Note: A palindrome is word, phrase,
or sequence that reads the same
backward as forward, e.g., madam
or nurses run.
Screenshot or paste your solution code here
Design / Flow chart
Extension
Write a Python program
to print the even numbers
from a given list.
Sample List : [1, 2, 3, 4,
5, 6, 7, 8, 9]
Expected Result : [2, 4,
6, 8]
Hint: use “enum.append”
Design / Flow chart