Initial work
This commit is contained in:
37
CS1032/practical-2023-10-04/tasks
Normal file
37
CS1032/practical-2023-10-04/tasks
Normal file
@@ -0,0 +1,37 @@
|
||||
based on user input, mapping "a" to "you chose the first option", "b" to "you chose the second option",
|
||||
"c" to "you chose the third option", otherwise "invalid choice"
|
||||
|
||||
# getting user input
|
||||
option = input ("Please enter a value for choice: ")
|
||||
|
||||
#verifying equality to "a"
|
||||
if option == "a":
|
||||
# printing message
|
||||
print (“you choose the first option”)
|
||||
# equality to b
|
||||
elif option == "b":
|
||||
# printing message
|
||||
print (“you choose the second option”)
|
||||
# equality to c
|
||||
elif option == "c":
|
||||
# printing message
|
||||
print (“you choose the third option”)
|
||||
#otherwise
|
||||
else:
|
||||
# printing message
|
||||
print("Invalid choice.")
|
||||
|
||||
Task 2
|
||||
x is undefined - prepend "x = int(input())\n"
|
||||
# if x is non-negative
|
||||
# if x less than 10
|
||||
# print message
|
||||
|
||||
Task 3
|
||||
x is undefined - prepend "x = int(input())\n"
|
||||
# if x is positive
|
||||
# increase x, inform user
|
||||
# otherwise
|
||||
# decrease x, inform user
|
||||
# print message
|
||||
|
||||
14
CS1032/practical-2023-10-04/workshop.py
Normal file
14
CS1032/practical-2023-10-04/workshop.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from typing import Iterable
|
||||
|
||||
def split(delim: str, s: str) -> Iterable[str]:
|
||||
while len(s):
|
||||
idx = s.find(delim)
|
||||
if idx == -1: idx = len(s)
|
||||
yield s[:idx]
|
||||
s = s[idx + len(delim):]
|
||||
|
||||
for x in split(", ", "Aberdeen, Dundee, Edinburgh, Glasgow"): print(x)
|
||||
|
||||
# Swap M and D names in the definitions
|
||||
d, m, y = tuple(split("/", "11/9/2001"))
|
||||
print(f"Day = {d}, Month = {m}, Year = {y}")
|
||||
Reference in New Issue
Block a user