1. 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.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s