Fresco Play Python3 Hands-On Solutions

1. Greeting Quote

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

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())

3. Get Additional Info

def docstring(functionname):
    # Write your code here
    help(functionname)
    
if __name__ == '__main__':

    x = input()
    docstring(x)

4. Name Space 2

def Prompt():
    # Write your code here
    x = input('Enter a STRING:\n')
    print(x)
    print(type(x))

5. Usage Imports

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)

6. Python Range 1

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

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

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 Int Math

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

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

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

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. Tab Spacing & New Line

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 Operation 2

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

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 Operation 2

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

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

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

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

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

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

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

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()

  For more answers refer below.


Comments