print("one word") # bu default adds new line at end of print
print("second line")one word
second line
one word
second line
name = "vikrant"
surname = "patil"
print(name , surname) # default seperator between the arguments is spacevikrant patil
print this and this also this third argument
sys.argv # this is a variable that takes command line arguments from cmd and stares in this variables['/opt/tljh/user/lib/python3.10/site-packages/ipykernel_launcher.py',
'-f',
'/home/jupyter-pipal/.local/share/jupyter/runtime/kernel-a8ab5199-2684-4627-843a-8eb1ba882b97.json']
['foo.py', 'argument1', 'argument2', 'dkjsfhsdjk', 'kdjfhjkasd', '1', '2', '3']
printargs.py
hello
let
me
test
this
script
1
2
3
4
Write a function flatten which combines nested lists into a single list. It takes a list of lists as an argument and returns a list of all elements from nested lists.
>>> flatten([[1,2,3],[4,5],[6,7,8,9]])
[1,2,3,4,5,6,7,8,9]
You can verify your solution using:
%verify_problem flatten
Write a program box.py that takes word as a command-line argument and prints the word in a box as shown below.
$ python box.py python
+--------+
| python |
+--------+
Please note that there should be exactly one space on either side of the text in the box.
You can verify your solution using:
%verify_problem text-in-a-box
Write a function unique which will remove duplicates from a list and maintain the order of items as in original list.
>>> unique([1, 1, 2, 3, 1, 2, 3, 2, 4])
[1, 2, 3, 4]
You can verify your solution using:
%verify_problem unique
u = []
Write a function mean to compute the arthematic mean of a list of numbers.
The arthemetic mean of N numbers is computed by adding all the N numbers and dividing the total by N.
The function takes the list of numbers as argument and returns the mean.
>>> mean([1, 2, 3, 4, 5])
3.0
You can verify your solution using:
%verify_problem mean
Write a function evens that takes a list of numbers as argument and returns a new list containing only the even numbers out of it.
>>> evens([1, 2, 3, 4, 5, 6])
[2, 4, 6]
You can verify your solution using:
%verify_problem evens
r = []
for item in givenlist:
if cond on item:
r.append(do somthing with item)
Write a program countdown.py to print numbers from n to 1.
The program should take the number n as command-line argument.
$ python countdown.py 5
5
4
3
2
1
You can verify your solution using:
%verify_problem countdown
In financial terms a negative balance is represented with round barackets around the number instead of - sign. Write a function numeric_value which returns actual numeric value. For example a value "(1234)" should get -1234 as numeric value. while "34" will get value as 34
>>> numeric_value("(1234)")
-1234
>>> numeric_value("42")
42
You can verify your solution using:
%verify_problem numeric-value
Write a function reverse_words that takes a sentence and returns a new sentence with all the words in the reserse order.
>>> reverse_words("joy of programming")
'programming of joy'
>>> reverse_words("less is more")
'more is less'
>>> reverse_words("road goes ever on and on")
'on and on ever goes road'
Please note that only the order of the words in the sentence is reversed, not the letters in each word.
You can verify your solution using:
%verify_problem reverse-words