From a9b392d3dbe744e7b08d5da4604ab4030ed04c90 Mon Sep 17 00:00:00 2001 From: Edward Bigos Date: Tue, 18 Mar 2025 10:20:16 -0400 Subject: [PATCH] Added if statement code --- README.md | 2 ++ if/if01.py | 32 ++++++++++++++++++++++++++++++++ if/if02.py | 39 +++++++++++++++++++++++++++++++++++++++ if/if03.py | 16 ++++++++++++++++ if/if04.py | 23 +++++++++++++++++++++++ if/if05.py | 25 +++++++++++++++++++++++++ if/if06.py | 7 +++++++ if/if07.py | 16 ++++++++++++++++ 8 files changed, 160 insertions(+) create mode 100644 if/if01.py create mode 100644 if/if02.py create mode 100644 if/if03.py create mode 100644 if/if04.py create mode 100644 if/if05.py create mode 100644 if/if06.py create mode 100644 if/if07.py diff --git a/README.md b/README.md index 0827612..83fe12b 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,6 @@ ### This is a third header +## This is a new header level 2 + Temp repository diff --git a/if/if01.py b/if/if01.py new file mode 100644 index 0000000..f3d834f --- /dev/null +++ b/if/if01.py @@ -0,0 +1,32 @@ + +program01 = ''' + +Program: if01 +This program demonstrates the conditional tests used in Python. + +''' + +print(program01) + +a = 4 +b = 7 +c = 7 + +print(f"a = {a}\nb = {b}\nc = {c}\n") + +print(f"a == b {a==b}") +print(f"a != b {a!=b}") +print(f"a < b {a b {a>b}") +print(f"a >= b {a>=b}") + +print("\n") + +print(f"c == b {c==b}") +print(f"c != b {c!=b}") +print(f"c < b {c b {c>b}") +print(f"c >= b {c>=b}") + diff --git a/if/if02.py b/if/if02.py new file mode 100644 index 0000000..b5f131c --- /dev/null +++ b/if/if02.py @@ -0,0 +1,39 @@ + +# if statement example +if 22 > 7: + print("22 is greater than 7") + +print("A better method to define the code ...") + +# Use variables in the if statement and print +data1 = 22 + + +if data1 > 7: + print(f"{data1} is greater than 7") + + +# Or this form +print("And another method to define the code ...") + + +data1 = 22 +data2 = 7 + +if data1 > data2: + print(f"{data1} is greater than {data2}") + + + + +data1 = 6 +data2 = 7 + +if data1 > data2: + print(f"{data1} is greater than {data2}") +else: + print(f"{data1} is less than or equal {data2}") + + +print("Program ended") + diff --git a/if/if03.py b/if/if03.py new file mode 100644 index 0000000..577511b --- /dev/null +++ b/if/if03.py @@ -0,0 +1,16 @@ + +# if..else statement example +x = 7 +print(f"{x} is equal to 7?") +if x == 7: + print("Yes") +else: + print("No") + +# if..else statement example +x = 5 +print(f"{x} is equal to 7?") +if x == 7: + print("Yes") +else: + print("No") diff --git a/if/if04.py b/if/if04.py new file mode 100644 index 0000000..00ae972 --- /dev/null +++ b/if/if04.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +# Program: if02 + +# Lists of numbers. These could be integers or floats. +intList = [7, 2, 16, 18, 12, 21] + +# Print the list and the length +print(intList," length = ",len(intList)) + +print(f"Print each value in the list") +counter = 0 +for item in intList: + print(f"intList[{counter}] = {item:2d}") + counter += 1 + +cutoff = 13 +print(f"Print each value in the list >= {cutoff}") +counter = 0 +for item in intList: + if(item >= cutoff): + print(f"intList[{counter}] = {item:2d}") + counter += 1 + diff --git a/if/if05.py b/if/if05.py new file mode 100644 index 0000000..fc31f8a --- /dev/null +++ b/if/if05.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +# Program: if03 + +# Lists of numbers. These could be integers or floats. +intList = [7, 2, 16, 18, 12, 21] + +# Print the list and the length +print(intList," length = ",len(intList)) + +print(f"Print each value in the list") +counter = 0 +for item in intList: + print(f"intList[{counter}] = {item:2d}") + counter += 1 + +cutoff = 13 +print(f"Print each value in the list >= {cutoff}") +counter = 0 +for item in intList: + if(item >= cutoff): + print(f"intList[{counter}] = {item:2d}") + else: + print(f"========> intList[{counter}] = {item:2d} is less than {cutoff}") + counter += 1 + diff --git a/if/if06.py b/if/if06.py new file mode 100644 index 0000000..bf9b1f5 --- /dev/null +++ b/if/if06.py @@ -0,0 +1,7 @@ + +# consider the following line from the autoloan program: + +principal = float(input("Enter a value for the principal: ")) + + +print(f"You entered the value {principal}") \ No newline at end of file diff --git a/if/if07.py b/if/if07.py new file mode 100644 index 0000000..8ce43f5 --- /dev/null +++ b/if/if07.py @@ -0,0 +1,16 @@ + +# consider the following line from the autoloan program: + +principal = float(input("Enter a value for the principal: ")) +if(principal < 5000.) or (principal >120000.00): + print(f"The loan value {principal} is outside the allowed limits.") + exit(-1) + +rate = float(input("Enter a value for the interest rate (7 for 7%): ")) + +numberOfYears = float(input("Enter the number of years for the loan: ")) + +print(f"You entered the principal value {principal}") +print(f"You entered the rate value {rate}%") +print(f"You entered the loan term value {numberOfYears} years") +