Skip to content

Commit 3f64e38

Browse files
authored
Add files via upload
1 parent fd58fe1 commit 3f64e38

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Basic Techniques of Programming.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
# coding: utf-8
3+
4+
# ### Read data from Console
5+
# To read data from console in Python, use the built-in function input(prompt_string)
6+
7+
# In[2]:
8+
9+
10+
anIntValue=input("Enter an integer value:")
11+
print ("The user has entered this value:", anIntValue)
12+
13+
14+
# ### Print Data to the Console
15+
#
16+
# To print data to the console, use the in-built function: print(a_string)
17+
18+
# In[3]:
19+
20+
21+
# Examples of using the print()function to print data to the console
22+
print("Examples of using print()function", "\n")
23+
x = 15
24+
print("This is the value of x:",x, "\n")
25+
y = 25
26+
print("This is the value of x:",x, "; This is the value of y:",y, ".\n")
27+
28+
29+
# ### Calculate Diameter and the circumference of a circle. In this scenario, the user inadvertently enters a negative value
30+
#
31+
32+
# In[5]:
33+
34+
35+
pi=3.14159
36+
radius=float(input("Enter radius: "))
37+
if (radius<0):
38+
print("This is an error. Enter radius greater than 0")
39+
radius=float(input("Enter radius: "))
40+
unit=input("Enter units: ") # unit: cms, inches,ft, m
41+
diameter= 2*radius
42+
circumference=diameter * pi
43+
print("Diameter: ",diameter,unit)
44+
print("Circumference: ",circumference,unit)
45+
46+
47+
# ### if Statements
48+
49+
# It is assumed that the registered office of a university asks one analyst to provide a solution to the following problem : Write a python program that can read from the console. The user enters a student's name and his/her level (freshman, ...senior).The program is expected to assign a numeric code that represents his/her priority to register courses. Students who have higher priority are allowed to register courses before those with lower priority. The code starts from 1(highest) that is assigned to seniors and increments by 1 for each lower level.Finally, the program prints out the student name, his/her level, and the code of priority to register courses in the same line
50+
51+
# In[7]:
52+
53+
54+
studentLevel= "Senior" # level: freshman, sophomore, junior, senior
55+
if(studentLevel =="Senior"):
56+
prioritytoRegister = 1
57+
elif(studentLevel =="Junior"):
58+
prioritytoRegister = 2
59+
elif(studentLevel =="Sophomore"):
60+
prioritytoRegister = 3
61+
elif(studentLevel =="Freshman"):
62+
prioritytoRegister = 4
63+
else:
64+
print("Invalid studentLevel!!!")
65+
66+
print("studentLevel:", studentLevel, "; Priority to register",prioritytoRegister, "\n")
67+

0 commit comments

Comments
 (0)