0% found this document useful (0 votes)
10 views2 pages

Python Code Snippets for Beginners

The document contains a series of Python code snippets demonstrating various programming concepts. These include printing strings, importing modules, handling dates and times, performing mathematical calculations, and manipulating user input. Each snippet showcases different functionalities such as creating lists and tuples, extracting file extensions, and performing arithmetic operations.

Uploaded by

Jay Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Python Code Snippets for Beginners

The document contains a series of Python code snippets demonstrating various programming concepts. These include printing strings, importing modules, handling dates and times, performing mathematical calculations, and manipulating user input. Each snippet showcases different functionalities such as creating lists and tuples, extracting file extensions, and performing arithmetic operations.

Uploaded by

Jay Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

print("Twinkle, twinkle, little star, \n\tHow I wonder what you are! \n\t\
tUp above the world so high, \n\t\tLike a diamond in the sky. \nTwinkle,
twinkle, little star, \n\tHow I wonder what you are!

2.

import sys
print("Python version")
print ([Link])
print("Version info.")
print (sys.version_info)

3.
import datetime
now = [Link]()
print ("Current date and time : ")
print ([Link]("%Y-%m-%d %H:%M:%S"))

4.
from math import pi
r = float(input ("Input the radius of the circle : "))
print ("The area of the circle with radius " + str(r) + " is:
" + str(pi * r**2))

5.
fname = input("Input your First Name : ")

lname = input("Input your Last Name : ")

print ("Hello " + lname + " " + fname)

6.
values = input("Input some comma seprated numbers : ")
list = [Link](",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)

7.
filename = input("Input the Filename: ")
f_extns = [Link](".")
print ("The extension of the file is : " + repr(f_extns[-1]))

8.
color_list = ["Red","Green","White" ,"Black"]
print( "%s %s"%(color_list[0],color_list[-1]))

9.
exam_st_date = (11,12,2014)

print( "The examination will start from : %i / %i / %i"%exam_st_date)

10.
a = int(input("Input an integer : "))
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)

You might also like