x = input("Enter value for x:") # any value that you enter using input function is textEnter value for x: 10
Enter value for x: 10
%%file say_hello.py
import sys
# argv variable inside sys module will have all the commandline arguments that you pass from commandline
sys.argv
print(sys.argv)Writing say_hello.py
%%file say_hello.py
import sys
# argv variable inside sys module will have all the commandline arguments that you pass from commandline
sys.argv
print("Hello", sys.argv[1])Overwriting say_hello.py
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
%%file box.py
# your code here
import sys
def print_a_box1(word):
dashcount = len(word)+2
line1 = "+" + "-"*dashcount + "+"
line2 = "| " + word + " |"
print(line1)
print("|",word,"|")
print(line1)
word = sys.argv[1] # get the word from command line
print_a_box1(word) # call the function with that word as argumentOverwriting box.py
✓ python box.py python
✓ python box.py Joy
✓ python box.py "Joy of Programming"
🎉 Congratulations! You have successfully solved problem text-in-a-box!!
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
3.0
✗ mean([1, 2, 3, 4, 5])
expected: 3.0
found: None
5.0
✗ mean([5])
expected: 5.0
found: None
💥 Oops! Your solution to problem mean is incorrect or incomplete.
Any function that does not return a value, actually returns None
Traceback (most recent call last):
File "/home/jupyter-vikrant/arcesium-python-2024/args.py", line 3, in <module>
print(sys.argv[1])
IndexError: list index out of range