Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# BertelsmanProjects
This contains some sample code challenges in the python community in Bertelsman scholarship program.
It contains simple programmes meant for beginners.
34 changes: 34 additions & 0 deletions no_more_pennies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
This programme will read prices from user until a blank line
is entered. It will then display the total cost of all the
entered items on one line, followed by the amount due if the
customer pays with cash to the nearest nickel on the second
line.

Input: Float
Output: String
"""
prices = []
while True:
price = input("Please, enter item price: ")
if price == "":
break
else:
prices.append(float(price))

total_amount = sum(prices)

amount_in_cents = (total_amount * 100)
amount_in_nickel = amount_in_cents // 5

if amount_in_cents % 5 >= 2.5:
amount_in_nickel += 1

# Total dollar amount to the nearest nickel
amount_due = amount_in_nickel / 20



print("")
print("Total amount: {:.2f}".format(total_amount))
print('Amount due for cash payment: {:.2f}'.format(amount_due))
1 change: 1 addition & 0 deletions notebook37899451f7.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n for filename in filenames:\n print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":1,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"\"\"\"\nPython project\n\nThis project receives an license plate number input from the user and classifies it as \neither old style plate number, new style plate number or invalid number\n\nInput: String\nOutput: String\n\"\"\"\n\nplate_num = input(\"Enter license plate number: \")\n\nif len(plate_num) == 6 and plate_num[-3:].isnumeric() and plate_num[:4].isupper():\n print('Number is valid old style license plate')\nelif len(plate_num) == 8 and plate_num[:4].isnumeric() and plate_num[5:].isupper():\n print('Number is valid new style license plate')\nelse:\n print('Invalid number')","execution_count":5,"outputs":[{"output_type":"stream","name":"stdout","text":"Enter license plate number: 1234JHGY\nNumber is valid new style license plate\n"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"\"\"\"\nThis programme simulates a spin of a roulette and displays the number that \nwas selected and all of the bets that must be payed. \nIt only covers the following bets:\n- Single number (1 to 36, 0, or 00)\n- Red versus Black\n- Odd versus Even\n- 1 to 18 versus 19 to 36\n\nInput: None\nOutput: String\n\"\"\"\n\nimport random\n\ngreen = [0, '00']\nred = list(range(1,10, 2)) + list(range(12,19, 2)) + \\\nlist(range(19, 28, 2)) + list(range(30, 37, 2))\nblack = [n for n in range(1, max(red)) if n not in red]\nroulette_wheel = red + black + green\n\nindex = random.randint(0, len(roulette_wheel) - 1)\nnum = roulette_wheel[index]\n\n\nprint(f'The spin resulted in {num}...')\nif 0 != num != '00':\n print(f'Pay {num}')\n if num in red:\n print(f'Pay Red')\n \n if num in black:\n print(f'Pay Black')\n \n if num % 2 == 0:\n print('Even')\n else:\n print('Odd')\n \n if 1 <= num <= 18:\n print(f'Pay 1 to 18')\n \n if 19 <= num <= 36:\n print(f'Pay 19 to 36')\nelse:\n if num == 0:\n print('Pay 0')\n else:\n print('Pay 00')","execution_count":37,"outputs":[{"output_type":"stream","text":"The spin resulted in 34...\nPay 34\nPay Red\nEven\nPay 19 to 36\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.7.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":4}
37 changes: 37 additions & 0 deletions perimeter_of_polygon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
This Program will accept x-y coordinate input of a polygon
from a user and then calculate the perimeter.

Input: Integer
Output: String
'''

coord = []
perimeter = 0
first_pass = False

while True:
if first_pass:
x = input('Enter the x part of the coordinate: (blank to quit): ')
else:
x = input('Enter the x part of the coordinate: ')
first_pass = True
if x == "":break

y = input("Enter the y part of the coordinate: ")
if y == "":break

x = int(x)
y = int(y)

# Collecting the coordinates
coord.append((x, y))

i = 0
while i < len(coord)-1:
perimeter += ((coord[i][0]-coord[i+1][0])**2 + (coord[i][1]-coord[i+1][1])**2)**0.5
i += 1

perimeter += ((coord[i][0]-coord[0][0])**2 + (coord[i][1]-coord[0][1])**2)**0.5

print(f'The perimeter of that polygon is {perimeter}')