Posts

Unix Shell Script Program List 1 to 10

SCRIPT-1 Write a shell script which reads your name and department and print a message. echo "What is your name?" read nm echo "In which department are you?" read dept echo "My name is $nm." echo "I'm a $dept Student." OUTPUT: $ ./a.sh What is your name? admin In which department are you? BCA My name is admin. I'm a BCA Student. SCRIPT - 2 Write a shell script to check whether numbers are same or not. echo "Enter first number" read a echo "Enter second number" read b if [ $a == $b ] then echo "a is equal to b" else echo "a is not equal to b" fi OUTPUT $ ./n1.sh Enter first number 30 Enter second number 20 a is not equal to b SCRIPT-3 Write a shell script to check number using if..else. echo "Enter number" read count if [ $count -eq 100 ] then echo "Count is 100" elif [ $count -gt 100 ] then echo "Count is greater than 100"

Python Program List 3

121.       Write a Python program to convert the distance (in feet) to inches, yards, and miles. d_ft = int(input("Input distance in feet: ")) d_inches = d_ft * 12 d_yards = d_ft / 3.0 d_miles = d_ft / 5280.0 print("The distance in inches is %i inches." % d_inches) print("The distance in yards is %.2f yards." % d_yards) print("The distance in miles is %.2f miles." % d_miles) Output: Input distance in feet: 100                                                                                     The distance in inches is 1200 inches.                                                                         The distance in yards is 33.33 yards.                                                                          The distance in miles is 0.02 miles. 222.       Write a Python program to convert seconds to day, hour, minutes and seconds. time = float(input("Input time in seconds: ")) day = time // (

Python Program List 2

111.       Write a Python program to get a string and print n (non-negative integer) copies of a given string using function. def larger_string(str, n):    result = ""    for i in range(n):       result = result + str    return result print(larger_string('patel', 2)) print(larger_string('.py', 3)) Output: patelpatel                                 .py.py.py 212.       Write a Python program to find whether a given number (accept from the user) is even or odd, print out an appropriate message to the user. num = int(input("Enter a number: ")) mod = num % 2 if mod > 0:     print("This is an odd number.") else:     print("This is an even number.") Output: Enter a number: 5                                                                                              This is an odd number. 313.       Write a Python program to test whether a passed letter is a vowel or not. def

Python Program List 1

11.       Write a Python program to get the Python version you are using. import sys print("Python version") print (sys.version) print("Version info.") print (sys.version_info)                 Output: Python version                                                                                                 3.5.2 (default, Sep 10 2016, 08:21:44)                                                                         [GCC 5.4.0 20160609]                                                                                            Version info.                                                                                                  sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0) 22.       Write a Python program to display the current date and time import datetime now = datetime.datetime.now() print ("Current date and time : ") print (now.strftime("%Y-%m-%d %H:%M:%S&qu

Python HTML Generator using Yattag Part 2

Python HTML Generator 5. Shortcut for nodes that contain only text If you're producing HTML or XML, you've probably realized that most tag nodes contain only text. In order to write these in a terser way, use the  line  method. doc, tag, text, line=Doc().ttl() with tag('ul', id='course'): line('li', 'BCA', klass="degree") line('li', 'BBA') line('li', 'BSW') You'll get: <ul id="course"> <li class="degree">BCA</li> <li>BBA</li> <li>BSW</li> </ul> Oh, I forgot to introduce the  ttl  method I just used in the example above. It works just like the  tagtext  method I've talked about in the beginning of the tutorial, but instead of returning the triplet  (doc, doc.tag, doc.text) , it returns the quadruplet  (doc, doc.tag, doc.text, doc.line) . 6. Indentation We've added indentation in the