Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are"
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are
print("Twinkle, twinkle, little star,")
print(" How I wonder what you are! ")
print(" Up above the world so high,")
print(" Like a diamond in the sky.")
print("Twinkle, twinkle, little star,")
print(" How I wonder what you are")
import sys
print("Python Version: ", sys.version)
Current date and time :
2014-07-05 14:34:14
import datetime
print("Current Date and Time: ", datetime.datetime.now())
4. Write a Python program that calculates the area of a circle based on the radius entered by the user.
Sample Output :
r = 1.1
Area = 3.8013271108436504
print("Area of Circle Program!!")
radius = float(input("Input Radius: "))
area_of_circle = (22/7) * radius ** 2
print("Area of Circle = ", area_of_circle)
5. Write a Python program that accepts the user's first and last name and prints them in reverse order with a space between them.
first_name = input("Input First Name: ")
last_name = input("Input last name: ")
print(last_name, first_name)
6. Write a Python program that accepts a sequence of comma-separated numbers from the user and generates a list and a tuple of those numbers.
Output :
List : ['3', ' 5', ' 7', ' 23']
Tuple : ('3', ' 5', ' 7', ' 23')
values = input("Input some values followed by commans: ")
list_value = values.split(",")
print(List: list_value)
print(Tuple: tuple(list_value))
7. Write a Python program that accepts a filename from the user and prints the extension of the file.
Output : java
file_name = input("Enter file name with its extension: ")
ext_split = file_name.split(".")
print("File Extension is:", ext_split[-1])
color_list = ["Red", "Green", "White", "Black"]
print(color_list[0], color_list[-1])
9. Write a Python program to display the examination schedule. (extract the date from exam_st_date).
Sample Output : The examination will start from : 11 / 12 / 2014
exam_st_date = (11, 12, 2014)
print("The examination will start from: ", exam_st_date[0], "/", exam_st_date[1], "/", exam_st_date[2])
n = int(input("Enter n value: "))
n1 = int("%s" % n)
n2 = int("%s%s" % (n, n))
n3 = int("%s%s%s" % (n, n, n))
print(n1 + n2 + n3)
11. Write a Python program to print the documents (syntax, description etc.) of Python built-in function(s).
Expected Result :
abs(number) -> number
Return the absolute value of the argument.
import calendar
month = int(input("Enter month: "))
year = int(input("Enter Year: "))
cal = calendar.month(year, month)
print(cal)
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example
from datetime import date
date1 = date(2014, 7, 29)
date2 = date(2014, 8, 3)
print("Remaining days: ", abs(date1 - date2))