Sololearn Python Basic Concepts
Which of these is a valid variable name in Python? a-variable-name a variable name A_VARIABLE_NAME
A_VARIABLE_NAME
Learning (Notes) The three major versions of Python are 1.x, 2.x and 3.x. These are subdivided into minor versions, such as 2.7 and 3.3. Code written for Python 3.x is guaranteed to work in all future versions. Both Python Version 2.x and 3.x are used currently.
An (interpreter) is a program that runs scripts written in an interpreted language such as Python.
Which of these statements is true? CPython is an implementation of Python Python 1.7 is the most widely used version Python code must be always compiled
CPython is an implementation of Python
Which lines are executed when a Python file is run? The first 100 lines The first line only Every line
Every line
Learning (Notes) Python: A high-level programming language, with applications in numerous areas, including web programming, scripting, scientific computing, and artificial intelligence.
It is very popular and used by organizations such as Google, NASA, the CIA, and Disney.
What is the result of this code? >>> x = "a" >>> x *= 3 print(x)
aaa
What is the output of this code? >>> word = input("Enter a word: ") Enter a word: cheese >>> print(word + ' shop') 'cheeseshop' cheese shop "cheeseshop"
cheese shop
What is the output of this code? >>> spam = "eggs">>> print(spam * 3) eggseggseggs "spamspamspam" spamspamspam
eggseggseggs
What is the output of this code? >>> print('print("print")')
print("print")
What is Python?
programming language
Which line of code produces an error? '5' + 6 3 + 4 "7" + 'eight' "one" + "2"
'5' + 6
What is the output of this code? >>> print(3 * '7')
'777'
What is the output of this code? >>> x = 4 >>> x *= 3 >>> print(x)
12
Fill in the blank with the output of this code. >>> 1 + 2 + 3 + 4.0 + 5
15.0
What is the output of this code? >>> x = 3 >>> num = 17 >>> print(num % x)
17/3 = 5 remainder 2 2
What is the output of this code? >>> spam = 2 >>> eggs = 3 >>> del spam >>> eggs = 4 >>> spam = 5 >>> print(spam * eggs)
20
What is the output of this code? >>> float("210" * int(input("Enter a number:" ))) Enter a number: 2 "420.0" 210210.0 "210210" 420
210210.0
What is the output of this code? >>> int("3" + "4") "7" 34 "34"
34
What is the result of this code? >>> 7%(5 // 2)
5/2*2 =4 remainder of 1
What does this code output? >>> 1 + 2 + 3
6
Which option is output by this code?>>> (4 + 8) / 2 A 6.0 B 6 C 8
6.0
Which of these will not be stored as a float? A 7 B 3/4 C 7.0
7
What is the output of this code? >>> spam = "7" >>> spam = spam + "0" >>> eggs = int(spam) + 3 >>> print(float(eggs)) 73.0 703 10.0
73.0
What is the output of this code? >>> x = 5 >>> y = x + 3 >>> y = int(str(y) + "2") >>> print(y)
82
Complete the code to create a string containing a double quote. >>> "_____"
>>> " \" "
Fill in the missing part of the output. >>> """First line second line""" 'First line second line'
>>> """First line second line""" 'First line \n second line'
Fill in the missing string. >>> "Hello " + '_______ 'Hello world'
>>> "Hello " + 'world' 'Hello world'
Complete the code to create a string containing "Hello world". >>> "Hello _________ " 'Hello world'
>>> "Hello World" 'Hello world'
Fill in the blank to make this code correct. >>> ( __?__5 - 1) * 3-18
>>> (-5 - 1) * 3 = 18
Fill in the blank to make this code correct. >>> (1 +____) ** 2 = 16
>>> (1 + 3) ** 2 = 16
Drag and drop the answer that will cause a ZeroDivisionError. >>> (17 + 94) / (-5 + _______ )
>>> (17 + 94) / (-5 + 5)
Simple Operations The minus sign indicates a negative number. Operations are performed on negative numbers, just as they are on positive ones. >>> -7 -7 >>> (-7 + 2) * (-4) 20
>>> -7 -7 >>> (-7 + 2) * (-4) 20
Simple Operations Dividing by zero in Python produces an error, as no answer can be calculated. >>> 11 / 0 Traceback (most recent call last): File "<stdin>", line 1, in<module> ZeroDivisionError: division by zero
>>> 11 / 0 Traceback (most recent call last): File "<stdin>", line 1, in<module> ZeroDivisionError: division by zero
Simple Operations Python also carries out multiplication and division, using anasterisk to indicate multiplication and a forward slash to indicate division. Use parentheses to determine which operations are performed first. >>> 2 * (3 + 4) 14 >>> 10 / 2 5.0
>>> 2 * (3 + 4) 14 >>> 10 / 2 5.0
Simple Operations Python has the capability of carrying out calculations. Enter a calculation directly into the Python console, and it will output the answer. >>> 2 + 2 4 >>> 5 + 4 - 3 6
>>> 2 + 2 4 >>> 5 + 4 - 3 6
Fill in the blank to prompt for user input. >>>____ ("Enter a number:")
>>> input ("Enter a number:")
Learning (Notes) Your First Program Let's start off by creating a short program that displays "Hello world!". In Python, we use the print statement to output text: >>> print('Hello world!') Hello world!
>>> print('Hello world!') Hello world!
Learning (Notes) Printing Text The print statement can also be used to output multiple lines of text.For Example: >>> print('Hello world!') Hello world! >>> print('Hello world!') Hello world! >>> print('Spam and eggs...') Spam and eggs...
>>> print('Hello world!') Hello world! >>> print('Hello world!') Hello world! >>> print('Spam and eggs...') Spam and eggs...
Fill in the blanks to declare a variable, add 5 to it and print its value. >>> x = 4 >>> x______ = 5 >>> print ______
>>> x = 4 >>> x__+__ = 5 >>> print (x)
Drag the correct answer to make the code work correctly. >>> x = 5 >>> y =_______ >>> print(x + y) 12 A) 7 B) =7 C) "7"
>>> x = 5 >>> y =___7____ >>> print(x + y) 12 A) 7
Fill in the blanks to print "Hi" >>>________("Hi")
>>>print("Hi")
Fill in the blank to output "ni ni ni". >>>_______ ('ni ni ni'
>>>print('ni ni ni')
