Skip to content

Commit c336074

Browse files
committed
if, loops, example
1 parent 8eb7415 commit c336074

File tree

6 files changed

+139
-0
lines changed

6 files changed

+139
-0
lines changed

if_else_elif/if_then.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Collect string / test length
2+
3+
4+
def main():
5+
str_to_check = input("Please enter a test string: ")
6+
7+
if len(str_to_check) < 6:
8+
print("Your string is too short.")
9+
print("Please enter a string with at least 6 chatacters.")
10+
11+
if __name__=='__main__':
12+
main()

if_else_elif/if_then_2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Prompt user to enter number / test if even or odd
2+
3+
4+
def main():
5+
number = int(input("Please enter an integer: "))
6+
7+
if number % 2 == 0:
8+
print("Your number is even.")
9+
else:
10+
print("Your number is odd.")
11+
12+
if __name__=='__main__':
13+
main()

if_else_elif/if_then_3.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Scalene triangle All sides have different lengths
2+
# Isosceles triangle Two sides have the same length
3+
# Scalene triangle All: sides are equal
4+
5+
def main():
6+
a = int(input("The length of side a = "))
7+
b = int(input("The length of side b = "))
8+
c = int(input("The length of side c = "))
9+
10+
if a != b and b != c and a != c:
11+
print("This is a scalene triangle.")
12+
elif a == b and b == c:
13+
print("This is an equilateral triangle.")
14+
else:
15+
print("This is an isosceles triangle.")
16+
17+
if __name__=='__main__':
18+
main()

loops/loops.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
a = list(range(10))
2+
3+
## 1 for loop example
4+
# for num in a:
5+
# print(num)
6+
7+
8+
## break , continue
9+
# for num in a:
10+
# if num == 4:
11+
# print('Found')
12+
# break
13+
# print(num)
14+
15+
# for num in a:
16+
# if num == 4:
17+
# print('Found')
18+
# continue
19+
# print(num)
20+
21+
## for in for, and range function
22+
# for num in range(1,7):
23+
# for latter in 'abc':
24+
# print(num,latter)
25+
26+
27+
## while loop example
28+
# x = 0
29+
#
30+
# while x < 10:
31+
# x += 1
32+
# print(x)
33+
34+
## while infinity
35+
# x = 0
36+
#
37+
# while True:
38+
# x += 1
39+
# print(x)

scripts/text.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Little afraid its eat looked now. Very ye lady girl them good me make. It hardly cousin me always. An shortly village is
2+
raising we shewing replied. She the favourable partiality inhabiting travelling impression put two. His six are entreaties
3+
instrument acceptance unsatiable her. Amongst as or on herself chapter entered carried no. Sold old ten are quit lose deal
4+
his sent. You correct how sex several far distant believe journey parties. We shyness enquire uncivil affixed it carried to.
5+
Literature admiration frequently indulgence announcing are who you her. Was least quick after six. So it yourself repeated
6+
together cheerful. Neither it cordial so painful picture studied if. Sex him position doubtful resolved boy expenses.
7+
Her engrossed deficient northward and neglected favourite newspaper. But use peculiar produced concerns ten.
8+
Impossible considered invitation him men instrument saw celebrated unpleasant. Put rest and must set kind next many near nay.
9+
He exquisite continued explained middleton am. Voice hours young woody has she think equal. Estate moment he at on
10+
wonder at season little. Six garden result summer set family esteem nay estate. End admiration mrs unreserved discovered
11+
comparison especially invitation.
12+
Ferrars all spirits his imagine effects amongst neither. It bachelor cheerful of mistaken. Tore has sons put upon wife use
13+
bred seen. Its dissimilar invitation ten has discretion unreserved. Had you him humoured jointure ask expenses learning.
14+
Blush on in jokes sense do do. Brother hundred he assured reached on up no. On am nearer missed lovers. To it mother extent
15+
temper figure better.
16+
Abilities forfeited situation extremely my to he resembled. Old had conviction discretion understood put principles you.
17+
Match means keeps round one her quick. She forming two comfort invited. Yet she income effect edward. Entire desire way
18+
design few. Mrs sentiments led solicitude estimating friendship fat. Meant those event is weeks state it to or. Boy but
19+
has folly charm there its. Its fact ten spot drew.
20+
Spot of come to ever hand as lady meet on. Delicate contempt received two yet advanced. Gentleman as belonging he commanded
21+
believing dejection in by. On no am winding chicken so behaved. Its preserved sex enjoyment new way behaviour.
22+
Him yet devonshire celebrated especially. Unfeeling one provision are smallness resembled repulsive.
23+
Why end might ask civil again spoil. She dinner she our horses depend. Remember at children by reserved to vicinity. In affronting unreserved delightful simplicity ye. Law own advantage furniture continual sweetness bed agreeable perpetual. Oh song well four only head busy it. Afford son she had lively living. Tastes lovers myself too formal season our valley boy. Lived it their their walls might to by young.
24+
Looking started he up perhaps against. How remainder all additions get elsewhere resources. One missed shy wishes supply design answer formed. Prevent on present hastily passage an subject in be. Be happiness arranging so newspaper defective affection ye. Families blessing he in to no daughter.
25+
Respect forming clothes do in he. Course so piqued no an by appear. Themselves reasonable pianoforte so motionless he as difficulty be. Abode way begin ham there power whole. Do unpleasing indulgence impossible to conviction. Suppose neither evident welcome it at do civilly uncivil. Sing tall much you get nor.
26+
Behaviour we improving at something to. Evil true high lady roof men had open. To projection considered it precaution an melancholy or. Wound young you thing worse along being ham. Dissimilar of favourable solicitude if sympathize middletons at. Forfeited up if disposing perfectly in an eagerness perceived necessary. Belonging sir curiosity discovery extremity yet forfeited prevailed own off. Travelling by introduced of mr terminated. Knew as miss my high hope quit. In curiosity shameless dependent knowledge up.

scripts/words_count.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Programm take txt file as argument count number of occurrences and print histo bar chart with number.
2+
3+
import sys
4+
5+
## via arguments :
6+
# file_name = sys.argv[1]
7+
## via console :
8+
9+
10+
def print_dictionary(dic, file_name):
11+
print("Word\tNumber of occurrences in {0}",file_name)
12+
for key in dic.keys():
13+
print(f"{key}-{dic[key]}")
14+
15+
def main():
16+
file_name = input("Please insert file name to work with: ")
17+
alpha_statistic = {}
18+
with open(file_name,'r') as f:
19+
lines = f.readlines()
20+
print(lines)
21+
for line in lines:
22+
for word in line.split():
23+
if word.rstrip() in alpha_statistic.keys():
24+
alpha_statistic[word]+=1
25+
else:
26+
alpha_statistic[word]=1
27+
28+
print_dictionary(alpha_statistic, file_name)
29+
30+
if __name__=='__main__':
31+
main()

0 commit comments

Comments
 (0)