#Some Python Examples for Practice -Basic Questions and then some a bit more Challenging

#Question 1
res = 14/5
res2 = 14%5

#Print out the results and these calculations and indicate if the result is an Integer or Float
################################################################################################

#Question 2

x=7
while x >4:
    if(x %3 ==0):
        break
    x = x-1
print("The Final value of X is: ",x)
#What do you expect the value of X to be?
###############################################################################################

#Question 3
x=7
while x >4:

    if x%6 ==0 :
        x=3
        continue

    if x%3 ==0:
        break

    x = x-1
print("Now the Final value of \"x\" is: ",x)
#What do you expect the value of "x" to be?
############################################################################################################

#Question 4

i = 0
while i < 3:
    print("testingtesting: ",i)
    i =i+1

#This programme while loop prints i but this begins at 0
#Change the code so it prints out the same number of times as before but prints numbers beginning from 1 1
##############################################################################################################

#Question 5
testq =False

if testq==False:
    if testq==True:
        testq=False
#Try to work out the value of testq at the end of the programme from reading the code
#Print out the result to confirm that you are correct!
################################################################################################################


#Challenge 1: An example hello world function-now with shouting..
def hi_world_shout(takecredit):
    takecredit = takecredit.upper()
    takecredit+="!!!"
    print("Hello World from ",takecredit)

    return "finished"

hi_world_shout("Simon")

#Notice I have changed the function to change the takecredit string to uppercase and add "!!"
#upper() is itself a function that returns the uppercase version of a string
#If I do not assign the result of this function to a variable (or use it in some way) then the conversion is lost
#takecredit.upper() does not make the original takecredit string uppercase- it returns a new version that is uppercase!

#Tasks to Complete:
#            Call the hi_world_shout function several times with different names
#            Change the code so it prints out the text four times per function call
#            Change the function so we can specify the number of times to repeat the printing of the text
#            Someone else using your function might specify lots of repeats to print-is this a problem?
#            Change the code to stop users entering too many print repeats.

########################################################################################################################



#Challenge 2: An example of a for loop iterating through a string
teststring = "this is a big string"

position =0
for v in teststring:
    if v=="a":
        print("Found \"a\" at position: ",position)
    position=position + 1

#teststring is assigned a string literal
#This string is then iterated one element (character) at a time searching for "a" characters
#Notice that I would like to output quotes in the printout but these are seen as bounding strings by Python
#So I escape the quotes using \" - this tell Python to print a quote rather than recognise this as a start or end of a string

#Tasks to Complete
#           At the moment the code prints out a line each time the "a" character is found
#           Change the code so that it terminates the for loop once the first character match is found
#           Modify the code so it works inside a function and the character being searched is passed as a function parameter

#############################################################################################################################


#Challenge 3: Write your own programme
teststring2 = "another task to try"

#Tasks to Complete
#         Write  some code that searches (iterates) through teststring2
#         If a 't' character print out a dialog that reports the position of the t
#         If a 'k' character is encountered,  exit searching and consider no further characters
#############################################################################################################################

#Challenge 4 Write a simple function that adds two number together
#This takes as input two numerical values and returns the result of the calculation
#Write another function that subtracts two numbers and returns the result
#Show how you can call the functions to solve 6+2-4

#Challenge 5 Write a simple function that is passed a variable and prints out the memory address, type and value of that variable
#By default the type() function prints out quite a messy string eg <class 'str'>,so for types we've discussed Integer, String, Boolean and Float
#Change this output so it is clearer. So you might want to output "String" instead of <class 'str'>
#Hint:- The string object has a function called "find" that will be quite useful for this task.

################################################################################################################################



