Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##------------------------------------------ Task 1 --------------------------------##
- ## Simple Calculator
- x = 10
- y = 20
- total = x + y
- print(total, type(total))
- x = 10
- y = 20
- total = x - y
- print(total, type(total))
- x = 10
- y = 20
- total = y / x
- print(total, type(total))
- x = 10
- y = 20
- total = y % x
- print(total)
- ## Type Conversion
- x = 10
- y = 5
- print( float(x) / float(y) )
- x = 100
- y = 5
- x_str = str(x)
- y_str = str(y)
- total = x_str + y_str
- print(total, type(total))
- x = "10"
- y = "5"
- x_int = int(x)
- y_int = int(y)
- total = x_int + y_int
- print(total,type(total))
- x = 99.8
- x_int = int(x)
- print(x_int, type(x_int))
- x = 5
- y = "5.2"
- z = 3
- x_float = float(x)
- y_float = float(y)
- z_float = float(z)
- print(x_float, type(x_float))
- print(y_float, type(y_float))
- print(z_float, type(z_float))
- ## Input function
- name = input("Enter your name : ")
- print("Good Morning", name)
- ## Calculator with input fn()
- first = input("Enter your first number : ")
- second = input("Enter your second number : ")
- third = input("What you want to do add/substract/divide : ")
- if third == "+":
- add = int(first) + int(second)
- print(add)
- if third == "-":
- sub = int(first) - int(second)
- print(sub)
- if third == "/":
- div = int(first) / int(second)
- print(div)
- ## Comparison operators
- x = 10
- y = 5
- r = x > y
- print("x > y", r)
- r = x < y
- print("x < y", r)
- r = x >= 20
- print("x >=20 ", r)
- r = x <= 10
- print( "x <= 10", r)
- r = x == y
- print("x == y", r)
- r = x == 10
- print("x == 10", r)
- r = x != 10
- print("x != 10", r)
- r = y != 10
- print("y != 10", r)
- ## String comparison
- str1 = "abc123"
- str2 = "abc123"
- str3 = "abc"
- result = str1 == str2
- print(result)
- result = str1 != str2
- print(result)
- result = str3 == str2
- print(result)
- ## Len function
- name1 = "prince"
- name2 = "chris"
- name3 = "Vysakh UT"
- result = len(name1)
- print(result, type(result))
- result = len(name2)
- print(result, type(result))
- result= len(name3)
- print(result, type(result))
- port = 8080
- result = len(str(port))
- print(result, type(result))
- ## Membership Operation
- fruit = "Pineapple"
- result = "apple" in fruit
- print(result)
- result = "in" in fruit
- print(result)
- result = "p" in fruit
- print(result)
- result = "P" not in fruit
- print(result)
- ## Subscript Operation
- name = "Richard"
- r = name[0]
- print(r)
- r = name[3]
- print(r)
- ## If else condition
- num = input("Enter a number : ")
- x_int = int(num)
- if x_int >= 10:
- print("The number is greater than 10")
- else:
- print("Sorry the number is less than 10")
- ##------------------------------------------ Task 2 --------------------------------##
- ## 1] Print the length of the string
- word = input("Enter the word so as to count the n.o of characters : ")
- print( "The length is : ", len(word))
- Ans] Enter the word so as to count the n.o of characters : Kerala
- The length is : 6
- ## 2] Check the substring is present
- word = input("Enter the word : ")
- sub = input("Which word to check : ")
- if sub in word:
- print("Yes there is", sub , "in the word", word)
- else:
- print("Sorry no match found")
- Ans ] Enter the word : Pineapple
- Which word to check : apple
- Yes there is apple in the word Pineapple
- ## 3] Check the number is odd or even
- num = input("Enter the number to check whether it's odd or even : ")
- x_num = int(num)
- if x_num % 2 == 0:
- print( "The n.o", x_num , "is even")
- else:
- print( "The n.o", x_num , "is odd")
- Ans] Enter the number to check whether it's odd or even : 5
- The n.o 5 is odd
- ## 4] check the word that starts with "a" or "A"
- word = input("Enter the word : ")
- check = word[0]
- if check == "a" or check == "A":
- print("okay")
- else:
- print("No")
- Ans] Enter the word : Apple
- okay
Advertisement
Add Comment
Please, Sign In to add comment