- This was more of a find around the library part.
# Write a Python program to get the Python version you are using. # Write a Python program to display the current date and time. import datetime import sys print(sys.version) print(datetime.datetime.now())
2. Fiddling around with another library
# Write a Python program which accepts the radius of a circle from the user and compute the area. import math radius = int(input("Enter the radius of the circle: ")) area1 = math.pi * pow(radius, 2) print(area1) area2 = math.pi * radius**2 print(area2)
So in this as we see, there are two ways in which we can print the area:
- Using math library, we can use the power function and pass on the value of our radius and the power to which it has to be raised.
- Other is explicitly calling the exponential function using double asterisk.
3. This was more of a slicing function
# Write a Python program which accepts the user's first and last name # and print them in reverse order with a space between them. name = input("Enter your name please: ") if len(name) > 0: print(name[::-1])
Slicing is a way in which we can split our set of string/number/lists and display certain set of characters from it.