Code Monkey home page Code Monkey logo

bootcamps_and_workshops's Introduction

Tasks for students

1. What will be the output of the following Python code? Explain.

a = [1,2]
b = [1,2]

c = [(x,y**2) for x in a for y in b] 
print(c)
  • a. [(1, 1), (1, 4), (2, 1), (2, 4)]
  • b. [(1, 1), (1, 2), (2, 1), (2, 2)]
  • c. [(1, 1), (1, 2), (2, 2), (2, 4)]
  • d. [(1, 1), (1, 4), (2, 1), (2, 2)]
  • e. Error

2. What will be the output of the following Python code? Explain.

a = [1,2,3,4,5,6,7,8,9,10]
print(a[-1:-5])
  • a. [2,3,4,5]
  • b. [5,4,3,2]
  • c. [10,9,8,7]
  • d. []
  • e. Error

3. What will be the output of the following Python Code? Explain.

def fn(data1, data2):
    return {data1, data2}

list1 = [1, 2, 3, 4, 5]
list2 = [5, 6, 7, 8, 9]

z= fn(tuple(list1),tuple(list2))

print(z, type(z))
  • a. {1:5, 2:6, 3:7, 4:8, 5:9} <class 'dict'>
  • b. {1, 2, 3, 4, 5, 6, 7, 8, 9} <class 'set'>
  • c. {[1, 2, 3, 4, 5], [5,6,7,8,9]} <class 'dict'>
  • d. {(1, 2, 3, 4, 5), (5, 6, 7, 8, 9)} <class 'set'>
  • e. Error

4. What will be the output of the following Python code? Explain.

def product(a, b):
    return a * b


def add(a, b):
    return a + b


answer = (product if True else add)(2, 3)
print(answer)
  • a. 5
  • b. 6
  • c. 11
  • d. Error

5. What will be the output and why it is so ?

d = {True: "guvi", 1: "Good night"}

print(d)

bootcamps_and_workshops's People

Contributors

rames4498 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.