0% found this document useful (0 votes)
5 views6 pages

Programming in Python

The document provides an overview of programming concepts, including definitions of programming, variables, and instructions understandable by computers. It covers Python-specific topics such as variable naming conventions, string methods, list operations, and error handling. Additionally, it includes examples and explanations of various programming tasks and functions in Python.

Uploaded by

ishaan.books29
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)
5 views6 pages

Programming in Python

The document provides an overview of programming concepts, including definitions of programming, variables, and instructions understandable by computers. It covers Python-specific topics such as variable naming conventions, string methods, list operations, and error handling. Additionally, it includes examples and explanations of various programming tasks and functions in Python.

Uploaded by

ishaan.books29
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
You are on page 1/ 6

Programming

1. What is programming?

Writing instructions understandable by a computer so as to automate tasks

2. What instructions are understandable by a computer?

A Computer system involves millions if not billions of transistors embedded on a silicon chip that as a sequential
result of deciding between the on states and off states (defined by ‘0’ and ‘1’, respectively) get capable running more
complex of tasks. The two states on (1) and off (0) are said to be binary.
It however becomes cumbersome detailing all the instructions in binary which led to development of more human
friendly languages over time which are then complied to machine code for the computer to understand.

3. What are variables?


Variables are named memory locations that hold values

4.Do labels(variable names)consume memory?

5. What are the conventions for naming a variable?(in Python)


a. Variable names can contain alphabets, numbers, and underscores but cannot begin with numbers 1_name is not
valid name_1 is valid
b. Variable names cannot contain spaces, underscores can be used to separate words
my program is invalid my_program is valid
c.Python keywords shouldn’t be used to create labels.

6. How do you print ,” I am ‘ishaan’ ,on the terminal”.


print("\"I am 'Ishaan',on the terminal\"")

7. What are the predefined methods for string used for?


a) <label>.title()  prints in title case
b) <label>.upper()  prints in upper case
c) <label>.lower()  prints in lower case
d) <label>.lstrip()  strips whitespace on the left side
e) <label>.rstrip()  strips whitespace on the right side
f) <label>.strip()  strips whitespaces on both sides
g) <label>.removeprefix()  removes given “prefixed-string” from a string/removes string by value
h) <label>.removesuffix()removes given “suffixed-string” from a string/removes string by value

8.What are f-Strings?[format]

9.How do you use a defined string into other string?

10.Write a Program to print the output as shown[\n,\t]


Languages:
Python
C
JavaScript
11.Suggest a workaround to not using removesuffix/removprefix [slicing,removes by position]
12.Correct the Syntax error in the following code snippet[f’’]
Var1=20-6
Var2=10+4
print(var1”/t”var2)
13.What is the use of triple quotes in python as opposed to double/single quotes? “””….””” [multi line comment,3]

14.What are docstrings?[comment in the first line]


15. Create a python list and print the same element but using different numbers[1,-1]

16. What are the predefined methods for lists used for?
<list_label>.append()
<list_label>.insert(index,element)
Del <list_label>[‘ ‘]
<list_label>.pop()
<list_label>.remove(“ “)
<list_label>.sort(reverse=”True”)
sorted(<list_label>)
<list_label>.reverse()
len(<list_label>)
min(<list_label>)
max(<list_label>)
sum(<list_label>)
list()
<list_label>[‘ ‘:’ ‘]
<list_label>.extend

17.What will be the output of the following code snippet


Motorcycles=['Honda','BMW',"KTM",'Ducati']
Motorcycles.insert(2,”Hero”)
print(Motorcycles)

18.Change the case of the last element in list and print it


Motorcycles=['Honda','BMW',"KTM",'Ducati']
19 What is the index of ‘Ducati’ in the above list?<-1>

20.How does <list_label>.pop() differ from del <list_label>.()


21.What value will <list_label>.pop() ‘pop’ if the arguments in pop function are made empty?
22Preet wants to remove ‘BMW’ from the list;
Motorcycles=['Honda','BMW',"KTM",'Ducati']
What function can he use? <remove()>

23Write the output for the following code snippet


motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati']
too_expensive = 'ducati'
motorcycles.remove(too_expensive) print(motorcycles)
24 How will you remove a value from a list so that it still remains accessible without using the pop() function?
25. Suggest ways to use both double and single quotes in a print statement
a. Use triple quotes
b. Use escape sequences <print(‘Ishaan won\’t be a pushover)
26. Function to remove item from a list by value 
27.Fn to remove item from a list by position 
28.Write the output to the following code snippet
name='Ishaan”
print(name[:3]
print(name[3:]
29. Create a list reverse sort and print using both sorted and sort function
Here is the required code snippet;
Cars=['bmw', 'audi', 'toyota', 'subaru']
print(sort(Cars,reverse=True)
Cars.sort(reverse=True)
print(Cars)
30. for loop in python returns output on different lines how can you print them on the same line?
list1=[0,1,2,3,4]
for numbs in list1:
print(numbs,end=” “)
31.
list=[0,1,2]
for number in list:
print(number,end=' ')
list1=[0,1,2,3,4]
for numbs in list1:
print(numbs,end=" ")
32.How can you change the printing of second iteration to the next line?
Inserting a print statement in between.
33. mylist=[1,2,3,4,5,6]
for num in mylist:
Run the entire iteration but print the last number
34. What is a logical error,explain with an example
35.What will be the output of the following program:
for num in range(6):
print(num)
36. List the even numbers between 1 and 10 ,using range() function
37. Make a list of the first 10 square numbers using for loop
38.Convert the following string literal into a list
Ishaan
39 Store first 10 square numbers using the range function then print them as a list

40. mylist=list(range(1,11))
for num in mylist:
a=num**2
mylist.append(a)
print(mylist)
why doesnt this print ?
41. Use list comprehension to print the list of first 20 cubes
42.What is a ‘slice’ in python?
43.Does slicing delete items from the original list?
44. Print the first second and fourth item using one line,for the following list
list1=['mango','apple','banana','orange','guava']
45. list1=['mango','apple','banana','orange','guava']
list2=[]
for i in [0,1,3]:
list2=list1
print(len(list2))
it returns 5?why?
46.How would you merge two lists? <+,.extendto,*unpacking>
47.For the given list,print the first three in three separate lines,without using decision control
players = ['charles', 'martina', 'michael', 'florence', 'eli']
for player in players[:3]:
print(player)
48. Iterate through a list in Python and print its elements while skipping every other element?
players=["Tanisha","Aditi,"Yashwantika","Divyanshi","Soumya"]
49.How would you append two elements to a list?<extend.([])>
50.Append two elements without using extend.() function
51.What is the use of the append function?

You might also like