Reverse a String
s = input("enter a string : ") # reverse a given string def palindrome(string): x = "" for i in string: x = i + x return x print(palindrome(s))
//Text character_name = "John" //Numeric character_age = 50.5678213 //Boolean is_male = True print("There once was a man named " + character_name + ", ") //Output : There once was a man named John, print("he was " + str(character_age) + " years old. ") //Output : he was 50.5678213 years old. character_name = "Mike" print("He really liked the name " + character_name + ", ") //Output : He really liked the name Mike, print("but didn't like being " + str(character_age) + ".") //Output : but didn't like being 50.5678213.
print(2) //Output : 2 print(2.0987) //Output : 2.0987 print(-2.0987) //Output : -2.0987 print(3 + 4.5) //Output : 7.5 print(3 - 4.5) //Output : -1.5 print(3 * 4.5) //Output : 13.5 print(3 / 4.5) //Output : 0.6666666666666666 print(3 * 4 + 5) //Output : 17 print(3 * (4 + 5)) //Output : 27 print(10 % 3) //Output : 1
my_num = 5 print(my_num) //Output : 5 print(str(my_num) + " is my favourite number.") //Output : 5 is my favourite number. print(-my_num) //Output : -5 print(abs(-my_num)) //Output : 5 print(pow(3, 2)) //Output : 9 print(pow(4, 6)) //Output : 4096 print(max(4, 6)) //Output : 6 print(min(4, 6)) //Output : 4 print(round(3.2)) //Output : 3 print(round(3.7)) //Output : 4
from math import * print(floor(3.2)) //Output : 3 print(floor(3.7)) //Output : 3 print(ceil(3.2)) //Output : 4 print(ceil(3.7)) //Output : 4 print(sqrt(36)) //Output : 6.0 print(sqrt(31)) //Output : 5.5677643628300215
print("Giraffe\nAcademy") //Output : Giraffe // Academy print("Giraffe\"Academy") //Output : Giraffe"Academy phrase = "Giraffe Academy" print(phrase.lower()) //Output : giraffe academy print("phrase.upper()) //Output : GIRAFFE ACADEMY print(str(phrase.isupper())) //Output : False print(str(phrase.upper().isupper())) //Output : True print(str(len(phrase))) //Output : 15 print(phrase[0]) //Output : G print(str(phrase.index("G"))) //Output : 0 print(phrase.replace("Giraffe", "Elephant")) //Output : Elephant Academy
employees.txt (before function call)
employee_file = open("../employees1.txt", "a") employee_file.write("Toby - Human Resources") employee_file.write("\nKelly - Customer Service") employee_file.close()
employees.txt (after function call)
Toby - Human Resources Kelly - Customer Service