week 3
This commit is contained in:
parent
1323073df1
commit
d3e90b1de1
3
week 3/Can you.....md
Normal file
3
week 3/Can you.....md
Normal file
@ -0,0 +1,3 @@
|
||||
Write a program that counts for the user. Let the user enter the starting number, the ending number, and the amount by which to count
|
||||
|
||||
Create a program that gets a message from the user and then prints it out backward
|
2
week 3/Can you.....py
Normal file
2
week 3/Can you.....py
Normal file
@ -0,0 +1,2 @@
|
||||
out = input("string: ")
|
||||
print(out[::-1])
|
7
week 3/Challenge - Check For Palindromes.md
Normal file
7
week 3/Challenge - Check For Palindromes.md
Normal file
@ -0,0 +1,7 @@
|
||||
Ask the user to input a sentence. Check whether it is a palindrome - i.e. it reads the same reading backwards, as forwards.
|
||||
|
||||
Hint: check the Python documentation for how to reverse a list or string.
|
||||
|
||||
You can look at this video to get some ideas for testing ;)
|
||||
|
||||
https://youtu.be/gAfIikFnvuI
|
2
week 3/Challenge - Check For Palindromes.py
Normal file
2
week 3/Challenge - Check For Palindromes.py
Normal file
@ -0,0 +1,2 @@
|
||||
out = input("string: ")
|
||||
print("Is palendrome",out[::-1] == out)
|
3
week 3/Checking for numbers.md
Normal file
3
week 3/Checking for numbers.md
Normal file
@ -0,0 +1,3 @@
|
||||
How to check inputs to make sure that expected numbers are actually numbers. There are a number of ways to do this but the easiest is probably to use a try and except block.
|
||||
|
||||
files: numbercheck.PNG
|
9
week 3/Checking for numbers.py
Normal file
9
week 3/Checking for numbers.py
Normal file
@ -0,0 +1,9 @@
|
||||
def int_input(text):
|
||||
while True:
|
||||
try:
|
||||
user_input = int(input(text))
|
||||
return user_input
|
||||
except Exception:
|
||||
print("error")
|
||||
else:
|
||||
break
|
3
week 3/Counting with a for loop.md
Normal file
3
week 3/Counting with a for loop.md
Normal file
@ -0,0 +1,3 @@
|
||||
When you write a program you may find that you need to count. In combination with the for loop, you can use Python's range( ) function to count in all kinds of ways.
|
||||
|
||||
files: counter.py
|
5
week 3/Loopy string.md
Normal file
5
week 3/Loopy string.md
Normal file
@ -0,0 +1,5 @@
|
||||
Understanding for Loops
|
||||
|
||||
All sequences are made up of elements. A string is a sequence in which each element is one character. A for loop marches through (or iterates over) a sequence one element at a time.
|
||||
|
||||
files: loopy_string.py
|
9
week 3/Rock, Paper Scissors.md
Normal file
9
week 3/Rock, Paper Scissors.md
Normal file
@ -0,0 +1,9 @@
|
||||
Design a program to emulate the game Rock, Paper, Scissors.
|
||||
|
||||
Use Ascii art to display the choices (http://chris.com/ascii/)
|
||||
|
||||
- Play against the computer (randomly generate an answer)
|
||||
|
||||
Code up your design
|
||||
|
||||
Test
|
26
week 3/Rock, Paper Scissors.py
Normal file
26
week 3/Rock, Paper Scissors.py
Normal file
@ -0,0 +1,26 @@
|
||||
rock="""
|
||||
_______
|
||||
---' ____)
|
||||
(_____)
|
||||
(_____)
|
||||
VK (____)
|
||||
---.__(___)
|
||||
|
||||
"""
|
||||
|
||||
paper="""
|
||||
_______
|
||||
---' ____)____
|
||||
______)
|
||||
_______)
|
||||
VK _______)
|
||||
---.__________)
|
||||
"""
|
||||
scissors="""
|
||||
_______
|
||||
---' ____)____
|
||||
______)
|
||||
__________)
|
||||
VK (____)
|
||||
---.__(___)
|
||||
"""
|
17
week 3/counter.py
Normal file
17
week 3/counter.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Counter
|
||||
# Demonstrates the range() function
|
||||
|
||||
print ("Counting:")
|
||||
for i in range(10):
|
||||
print (i)
|
||||
|
||||
print ("\n\nCounting by fives:")
|
||||
for i in range(0, 50, 5):
|
||||
print (i)
|
||||
|
||||
print ("\n\nCounting backwards:")
|
||||
for i in range(10, 0, -1):
|
||||
print (i)
|
||||
|
||||
x = input("\n\nPress the enter key to exit.\n")
|
||||
|
10
week 3/loopy_string.py
Normal file
10
week 3/loopy_string.py
Normal file
@ -0,0 +1,10 @@
|
||||
# Loopy String
|
||||
# Demonstrates the for loop with a string
|
||||
|
||||
word = input("Enter a word: ")
|
||||
|
||||
print ("\nHere's each letter in your word:")
|
||||
for letter in word:
|
||||
print (letter)
|
||||
|
||||
x = input("\n\nPress the enter key to exit.")
|
BIN
week 3/numbercheck.PNG
Normal file
BIN
week 3/numbercheck.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Loading…
x
Reference in New Issue
Block a user