Python 3 Programming Hands-on Solution | TCS Fresco Play (2024)

Python 3 Programming Hands-on Solution | TCS Fresco Play (1)

Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.

Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions)

The Course id of Python 3 Programming is55193.

1. Print

Python 3 Programming Hands-on Solution | TCS Fresco Play (2)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Greet' function below.

#

# The function accepts STRING Name as parameter.

#

def Greet(Name):

# Write your code here

print("Welcome " + Name + ".")

print("It is our pleasure inviting you.")

print("Have a wonderful day.")

if __name__ == '__main__':

Name = input()

Greet(Name)

2. Namespaces 1

Python 3 Programming Hands-on Solution | TCS Fresco Play (3)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Assign' function below.

#

# The function accepts following parameters:

# 1. INTEGER i

# 2. FLOAT f

# 3. STRING s

# 4. BOOLEAN b

#

def Assign(i, f, s, b):

# Write your code here

w = i

x = f

y = s

z = b

print(w)

print(x)

print(y)

print(z)

print(dir())

if __name__ == '__main__':

i = int(input().strip())

f = float(input().strip())

s = input()

b = input().strip()

Assign(i, f, s, b)

3. Handson - Python - Get Additional Info

Python 3 Programming Hands-on Solution | TCS Fresco Play (4)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'docstring' function below.

#

# The function is expected to output a STRING.

# The function accepts STRING x as parameter.

#

def docstring(functionname):

# Write your code here

help(functionname)

if __name__ == '__main__':

x = input()

docstring(x)

4. Name Space 2

Python 3 Programming Hands-on Solution | TCS Fresco Play (5)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Prompt' function below.

#

#

def Prompt():

# Write your code here

x = input('Enter a STRING:\n')

print(x)

print(type(x))

if __name__ == '__main__':

Prompt()

5.Handson - Python - Usage imports

Python 3 Programming Hands-on Solution | TCS Fresco Play (6)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'calc' function below.

#

# The function is expected to return an INTEGER.

# The function accepts INTEGER c as parameter.

#

def calc(c):

# Write your code here

r = c/(2*math.pi)

a = r*r*math.pi

x = round(r,2)

y = round(a,2)

return(x,y)

if __name__ == '__main__':

fptr = open(os.environ['OUTPUT_PATH'], 'w')

c = int(input().strip())

result = calc(c)

fptr.write(str(result) + '\n')

fptr.close()

6. Python Range1

Python 3 Programming Hands-on Solution | TCS Fresco Play (7)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'func' function below.

#

# The function is expected to print an INTEGER.

# The function accepts following parameters:

# 1. INTEGER startvalue

# 2. INTEGER endvalue

# 3. INTEGER stepvalue

#

def rangefunction(startvalue, endvalue, stepvalue):

# Write your code here

for i in range(startvalue,endvalue,stepvalue):

print(i*i,end = "\t")

if __name__ == '__main__':

x = int(input().strip())

y = int(input().strip())

z = int(input().strip())

rangefunction(x, y, z)

7. Using int

Python 3 Programming Hands-on Solution | TCS Fresco Play (8)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Integer_fun' function below.

#

# The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. FLOAT a

# 2. STRING b

#

def Integer_fun(a, b):

# Write your code here

c = int(a)

d = int(b)

print(type(a))

print(type(b))

print(c)

print(d)

print(type(c))

print(type(d))

if __name__ == '__main__':

a = float(input().strip())

b = input()

Integer_fun(a, b)

8. Using Int operations

Python 3 Programming Hands-on Solution | TCS Fresco Play (9)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'find' function below.

#

# The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. INTEGER num1

# 2. INTEGER num2

# 3. INTEGER num3

#

def find(num1, num2, num3):

# Write your code here

print(num1<num2 and num2 >= num3,end=" ")

print(num1>num2 and num2 <= num3,end=" ")

print(num3 == num1 and num1!=num2,end=" ")

if __name__ == '__main__':

num1 = int(input().strip())

num2 = int(input().strip())

num3 = int(input().strip())

find(num1, num2, num3)

9. Using intMath Operations

Python 3 Programming Hands-on Solution | TCS Fresco Play (10)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Integer_Math' function below.

#

# The function accepts following parameters:

# 1. INTEGER Side

# 2. INTEGER Radius

#

def Integer_Math(Side, Radius):

# Write your code here

a = Side * Side

b = Side * Side * Side

c = 3.14 * Radius * Radius

x = round(c,2)

d = (4/3)*3.14*Radius*Radius*Radius

y = round(d,2)

print("Area of Square is "+ str(a))

print("Volume of Cube is "+ str(b))

print("Area of Circle is "+ str(x))

print("Volume of Sphere is "+ str(y))

if __name__ == '__main__':

Side = int(input().strip())

Radius = int(input().strip())

Integer_Math(Side, Radius)

10. Using Float 1

Python 3 Programming Hands-on Solution | TCS Fresco Play (11)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'tria' function below.

#

# The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. FLOAT n1

# 2. FLOAT n2

# 3. INTEGER n3

#

def triangle(n1, n2, n3):

# Write your code here

x = round((n1 * n2)/2,n3)

y = round(math.pi,n3)

return x,y

if __name__ == '__main__':

fptr = open(os.environ['OUTPUT_PATH'], 'w')

n1 = float(input().strip())

n2 = float(input().strip())

n3 = int(input().strip())

result = triangle(n1, n2, n3)

fptr.write(str(result) + '\n')

fptr.close()

11. Using float 2

Python 3 Programming Hands-on Solution | TCS Fresco Play (12)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Float_fun' function below.

#

# The function accepts following parameters:

# 1. FLOAT f1

# 2. FLOAT f2

# 3. INTEGER Power

#

def Float_fun(f1, f2, Power):

# Write your code here

print("#Add")

print(f1+f2)

print("#Subtract")

print(f1-f2)

print("#Multiply")

print(f1*f2)

print("#Divide")

print(f2/f1)

print("#Remainder")

print(f1%f2)

print("#To_The_Power_Of")

a = f1 ** Power

print(a)

print("#Round")

print(round(a,4))

if __name__ == '__main__':

f1 = float(input().strip())

f2 = float(input().strip())

Power = int(input().strip())

Float_fun(f1, f2, Power)

12. String Operations - 1

Python 3 Programming Hands-on Solution | TCS Fresco Play (13)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'strng' function below.

#

# The function is expected to return an INTEGER.

# The function accepts following parameters:

# 1. STRING fn

# 2. STRING ln

# 3. STRING para

# 4. INTEGER number

#

def stringoperation(fn, ln, para, number):

# Write your code here

print(fn+'\n'*number+ln)

print(fn+" "+ln)

print(fn*number)

print(f"The sentence is {para}")

if __name__ == '__main__':

fn = input()

ln = input()

para = input()

no = int(input().strip())

stringoperation(fn, ln, para, no)

13. Newline and Tab Spacing

Python 3 Programming Hands-on Solution | TCS Fresco Play (14)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'Escape' function below.

#

# The function accepts following parameters:

# 1. STRING s1

# 2. STRING s2

# 3. STRING s3

#

def Escape(s1, s2, s3):

# Write your code here

s = "Python\tRaw\nString\tConcept"

print(s1+'\n'+s2+'\n'+s3)

print(s1+'\t'+s2+'\t'+s3)

print(s)

s = r"Python\tRaw\nString\tConcept"

print(s)

if __name__ == '__main__':

s1 = input()

s2 = input()

s3 = input()

Escape(s1, s2, s3)

14. String Operations 2

Python 3 Programming Hands-on Solution | TCS Fresco Play (15)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'resume' function below.

#

# The function is expected to print a STRING.

# The function accepts following parameters:

# 1. STRING first

# 2. STRING second

# 3. STRING parent

# 4. STRING city

# 5. STRING phone

# 6. STRING start

# 7. STRING strfind

# 8. STRING string1

#

def resume(first, second, parent, city, phone, start, strfind, string1):

# Write your code here

print(first.strip().capitalize()+" "+second.strip().capitalize()+" "+parent.strip().capitalize()+" "+city.strip())

print(phone.isdigit())

print(phone.startswith(start))

print(first.count(strfind)+second.count(strfind)+parent.count(strfind)+city.count(strfind))

print(string1.split())

print(city.find(strfind))

if __name__ == '__main__':

a = input()

b = input()

c = input()

d = input()

ph = input()

no = input()

ch = input()

str = input()

resume(a, b, c, d, ph, no, ch, str)

15. List Operations 1

Python 3 Programming Hands-on Solution | TCS Fresco Play (16)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'List_Op' function below.

#

# The function accepts following parameters:

# 1. LIST Mylist

# 2. LIST Mylist2

#

def List_Op(Mylist, Mylist2):

# Write your code here

print(Mylist)

print(Mylist[1])

for i in range(len(Mylist)):

if(i==len(Mylist)-1):

print(Mylist[i])

Mylist.append(3)

for i in range(len(Mylist)):

if( i == 3 ):

Mylist[i] = 60

print(Mylist)

print(Mylist[1:5])

Mylist.append(Mylist2)

print(Mylist)

Mylist.extend(Mylist2)

print(Mylist)

Mylist.pop()

print(Mylist)

print(len(Mylist))

if __name__ == '__main__':

qw1_count = int(input().strip())

qw1 = []

for _ in range(qw1_count):

qw1_item = int(input().strip())

qw1.append(qw1_item)

qw2_count = int(input().strip())

qw2 = []

for _ in range(qw2_count):

qw1_item = int(input().strip())

qw2.append(qw1_item)

List_Op(qw1,qw2)

16. List Operations 2

Python 3 Programming Hands-on Solution | TCS Fresco Play (17)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'tuplefun' function below.

#

# The function accepts following parameters:

# 1. LIST list1

# 2. LIST list2

# 3. STRING string1

# 4. INTEGER n

#

def tuplefunction(list1, list2, string1, n):

# Write your code here

tuple1 = tuple(list1)

tuple2 = tuple(list2)

tuple3 = tuple1 + tuple2

print(tuple3)

print(tuple3[4])

tuple4 = (tuple1,tuple2)

print(tuple4)

print(len(tuple4))

print((string1,)*n)

print(max(tuple1))

if __name__ == '__main__':

qw1_count = int(input().strip())

qw1 = []

for _ in range(qw1_count):

qw1_item = int(input().strip())

qw1.append(qw1_item)

qw2_count = int(input().strip())

qw2 = []

for _ in range(qw2_count):

qw1_item = input()

qw2.append(qw1_item)

str1 = input()

n = int(input().strip())

tuplefunction(qw1,qw2,str1, n)

17. Python - Slicing

Python 3 Programming Hands-on Solution | TCS Fresco Play (18)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'sliceit' function below.

#

# The function accepts List mylist as parameter.

#

def sliceit(mylist):

# Write your code here

a = slice(1,3)

print(mylist[a])

b = slice(1,len(mylist),2)

print(mylist[b])

c = slice(-1,-4,-1)

print(mylist[c])

if __name__ == '__main__':

mylist_count = int(input().strip())

mylist = []

for _ in range(mylist_count):

mylist_item = input()

mylist.append(mylist_item)

sliceit(mylist)

18. Python - Range

Python 3 Programming Hands-on Solution | TCS Fresco Play (19)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'generateList' function below.

#

# The function accepts following parameters:

# 1. INTEGER startvalue

# 2. INTEGER endvalue

#

def generateList(startvalue, endvalue):

# Write your code here

list1 = list(range(startvalue,endvalue+1))

print(list1[:3])

list2 = list1[::-1]

print(list2[0:5])

print(list1[::4])

print(list2[::2])

if __name__ == '__main__':

startvalue = int(input().strip())

endvalue = int(input().strip())

generateList(startvalue, endvalue)

19. Python - Set

Python 3 Programming Hands-on Solution | TCS Fresco Play (20)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'setOperation' function below.

#

# The function is expected to return a union, intersection, difference(a,b), difference(b,a), symmetricdifference and frozen set.

# The function accepts following parameters:

# 1. List seta

# 2. List setb

#

def setOperation(seta, setb):

# Write your code here

seta = set(seta)

setb = set(setb)

union = seta.union(setb)

intersection = seta.intersection(setb)

diff1 = seta.difference(setb)

diff2 = setb.difference(seta)

symdiff = seta.symmetric_difference(setb)

frozenseta = frozenset(seta)

return(union, intersection, diff1, diff2, symdiff, frozenseta )

if __name__ == '__main__':

seta_count = int(input().strip())

seta = []

for _ in range(seta_count):

seta_item = input()

seta.append(seta_item)

setb_count = int(input().strip())

setb = []

for _ in range(setb_count):

setb_item = input()

setb.append(setb_item)

un, intersec, diffa, diffb, sydiff, frset = setOperation(seta, setb)

print(sorted(un))

print(sorted(intersec))

print(sorted(diffa))

print(sorted(diffb))

print(sorted(sydiff))

print("Returned value is {1} frozenset".format(frset, "a" if type(frset) == frozenset else "not a"))

20. Python Dictionary

Python 3 Programming Hands-on Solution | TCS Fresco Play (21)

#!/bin/python3

import math

import os

import random

import re

import sys

from pprint import pprint as print

#

# Complete the 'myDict' function below.

#

# The function accepts following parameters:

# 1. STRING key1

# 2. STRING value1

# 3. STRING key2

# 4. STRING value2

# 5. STRING value3

# 6. STRING key3

#

def myDict(key1, value1, key2, value2, value3, key3):

# Write your code here

dict1 = {key1:value1}

print(dict1)

dict1[key2] = value2

print(dict1)

dict1[key1] = value3

print(dict1)

dict1.pop(key3)

return dict1

if __name__ == '__main__':

key1 = input()

value1 = input()

key2 = input()

value2 = input()

value3 = input()

key3 = input()

mydct = myDict(key1, value1, key2, value2, value3, key3)

print(mydct if type(mydct) == dict else "Return a dictionary")

21. While Loop

Python 3 Programming Hands-on Solution | TCS Fresco Play (22)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'calculateNTetrahedralNumber' function below.

#

# The function is expected to return an INTEGER_ARRAY.

# The function accepts following parameters:

# 1. INTEGER startvalue

# 2. INTEGER endvalue

#

def calculateNTetrahedralNumber(startvalue, endvalue):

# Write your code here

list1 = list()

i = startvalue

while i<= endvalue:

num = (i*(i+1)*(i+2)/6)

list1.append(int(num))

i = i + 1

return list1

if __name__ == '__main__':

fptr = open(os.environ['OUTPUT_PATH'], 'w')

startvalue = int(input().strip())

endvalue = int(input().strip())

result = calculateNTetrahedralNumber(startvalue, endvalue)

fptr.write('\n'.join(map(str, result)))

fptr.write('\n')

fptr.close()

22. For Loop:-

Python 3 Programming Hands-on Solution | TCS Fresco Play (23)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'sumOfNFibonacciNumbers' function below.

#

# The function is expected to return an INTEGER.

# The function accepts INTEGER n as parameter.

#

def sumOfNFibonacciNumbers(n):

# Write your code here

first = 0

second = 1

result = 1

if n <= 1:

return 0

else:

for elem in range(2,n):

next = first + second

result = result + next

first = second

second = next

return result

if __name__ == '__main__':

fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input().strip())

result = sumOfNFibonacciNumbers(n)

fptr.write(str(result) + '\n')

fptr.close()

23. If Condition

Python 3 Programming Hands-on Solution | TCS Fresco Play (24)

#!/bin/python3

import math

import os

import random

import re

import sys

#

# Complete the 'calculateGrade' function below.

#

# The function is expected to return a STRING_ARRAY.

# The function accepts 2D_INTEGER_ARRAY students_marks as parameter.

#

def calculateGrade(students_marks):

# Write your code here

list1 = list()

for i in range(len(students_marks)):

count = 0

sum = 0

avg = 0

for j in range(len(students_marks[i])):

count = count + 1

sum = sum + students_marks[i][j]

avg = sum/count

if avg >= 90:

list1.append("A+")

elif avg >= 80:

list1.append("A")

elif avg >= 70:

list1.append("B")

elif avg >= 60:

list1.append("C")

elif avg >= 50:

list1.append("D")

elif avg < 50:

list1.append("F")

return list1

if __name__ == '__main__':

fptr = open(os.environ['OUTPUT_PATH'], 'w')

students_marks_rows = int(input().strip())

students_marks_columns = int(input().strip())

students_marks = []

for _ in range(students_marks_rows):

students_marks.append(list(map(int, input().rstrip().split())))

result = calculateGrade(students_marks)

fptr.write('\n'.join(result))

fptr.write('\n')

fptr.close()

If you have any queries, please feel free to ask on the comment section.

If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.

Python 3 Programming Hands-on Solution  |  TCS Fresco Play (2024)

FAQs

What is range in Python handson? ›

Handson - Python - Range Python - Range Define a function called "generatelist which takes two parameters The first parameter is startvalue and the next parameter is endvalue. The function definition code stub is given in the editor.

Which of the following is a correct program to print Hello World as output in Python? ›

Using the print() function

The print() function is one of the most frequently used functions in Python. It outputs text. Let's see it in action: print("Hello World!")

What does == mean in Python? ›

The “==” operator is known as the equality operator. The operator will return “true” if both the operands are equal. However, it should not be confused with the “=” operator or the “is” operator. “=” works as an assignment operator. It assigns values to the variables.

What does += mean in Python? ›

The plus-equals operator += provides a convenient way to add a value to an existing variable and assign the new value back to the same variable.

How to code Hello World in Python? ›

print("Hello, World!") The print() function is foundational, and mastering it will serve you well in your Python journey. It accepts one or more arguments, making it versatile enough to display strings, variables, or even complex expressions as output.

How to greet in Python? ›

Write a function called greet() that takes one string parameter called name and displays the text "Hello, <name>!" , where the name is replaced by the value of the name parameter. 00:33 For example, when you pass in "Lyra" into the greet() function, then the function should display "Hello, Lyra!" .

What is hello in Python? ›

It is used to illustrate the syntax of the programming language. Hello world in python is a line of code that prints the words ” Hello world ” on the output screen.

What is a range in Python? ›

Python range is a function that returns a sequence of numbers. By default, range returns a sequence that begins at 0 and increments in steps of 1. The range function only works with integers. Other data types like float numbers cannot be used.

Is range in Python lazy? ›

First, note that a range is a lazy sequence. This means that Python doesn't create the individual elements of a range when you create the range. Instead, it creates each element when you ask for it, for example by iterating over the range. The range object is lazy.

Why is range a data type in Python? ›

Python Range Data Type

Range() in Python is a built-in function that returns a series of numbers that begin at 0 and increase by 1 until they reach a predetermined number. Utilizing a for and while loop in python, we use the range() method to produce a series of numbers.

What is the range position in Python? ›

range() is a built-in function in Python that takes three parameters: start , stop , and step . start is the beginning of the sequence, stop specifies where to end, and step defines the increment between numbers. With a single argument, range() starts at 0 , increments by 1 , and stops at the specified value.

References

Top Articles
All the New Openings to Know About This June
Columbus Zoo - tickets, prijzen, tijden, korting, dieren om te zien, attracties
Knoxville Tennessee White Pages
360 Training Alcohol Final Exam Answers
Calamity Hallowed Ore
Matthew Rotuno Johnson
DIN 41612 - FCI - PDF Catalogs | Technical Documentation
What Was D-Day Weegy
Regal Stone Pokemon Gaia
Watch TV shows online - JustWatch
Sand Castle Parents Guide
Straight Talk Phones With 7 Inch Screen
Chelactiv Max Cream
Video shows two planes collide while taxiing at airport | CNN
Divina Rapsing
10 Fun Things to Do in Elk Grove, CA | Explore Elk Grove
The Pretty Kitty Tanglewood
U Of Arizona Phonebook
Lakewood Campground Golf Cart Rental
Ivegore Machete Mutolation
All Obituaries | Gateway-Forest Lawn Funeral Home | Lake City FL funeral home and cremation Lake City FL funeral home and cremation
Dewalt vs Milwaukee: Comparing Top Power Tool Brands - EXTOL
Bidevv Evansville In Online Liquid
Page 2383 – Christianity Today
Arlington Museum of Art to show shining, shimmering, splendid costumes from Disney Archives
2023 Ford Bronco Raptor for sale - Dallas, TX - craigslist
Sensual Massage Grand Rapids
8002905511
Tactical Masters Price Guide
Gopher Hockey Forum
Utexas Baseball Schedule 2023
Aladtec Login Denver Health
Most popular Indian web series of 2022 (so far) as per IMDb: Rocket Boys, Panchayat, Mai in top 10
Walter King Tut Johnson Sentenced
Serenity Of Lathrop - Manteca Photos
Insideaveritt/Myportal
R/Moissanite
How To Upgrade Stamina In Blox Fruits
Shane Gillis’s Fall and Rise
2007 Jaguar XK Low Miles for sale - Palm Desert, CA - craigslist
Craigs List Hartford
Cl Bellingham
Weather In Allentown-Bethlehem-Easton Metropolitan Area 10 Days
Trivago Anaheim California
R/Gnv
Gt500 Forums
Beds From Rent-A-Center
tampa bay farm & garden - by owner "horses" - craigslist
Costner-Maloy Funeral Home Obituaries
Divisadero Florist
Deviantart Rwby
Skybird_06
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 5736

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.