-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solutions-from-ex-17-to-31 #2982
Open
Dan90git
wants to merge
2
commits into
tomorrowdevs-projects:main
Choose a base branch
from
Dan90git:solutions-ex-17-to-32
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#import math module | ||
import math | ||
|
||
# ask to user a year | ||
year = int(input('Type a year: ')) | ||
|
||
# using the gived formula determinate wich day is the first of the year typed | ||
first_day = (year + math.floor((year - 1) / 4) - math.floor(year - 1 / 100) + math.floor(year - 1) / 400) % 7 | ||
|
||
# if statement the convert the number gived by formula to the name of the day and print on screen | ||
if first_day < 1: | ||
print('Sunday') | ||
elif first_day < 2: | ||
print('Monday') | ||
elif first_day < 3: | ||
print('Tuesday') | ||
elif first_day < 4: | ||
print('Wednesday') | ||
elif first_day < 5: | ||
print('Thursday') | ||
elif first_day < 6: | ||
print('Friday') | ||
elif first_day < 7: | ||
print('Saturday') | ||
else: | ||
print('error') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#import random module | ||
import random | ||
|
||
# use random function to get a number | ||
choice = random.choice(range(0,39)) | ||
|
||
# if statement that print on screen wich is number and the other cases that pay like a roulette | ||
if choice % 2 == 0 and choice != 37 and choice != 0: | ||
print(f'pay {choice}') | ||
print('pay black') | ||
print('pay even') | ||
elif choice % 2 != 0 and choice != 37: | ||
print(f'pay {choice}') | ||
print('pay red') | ||
print('pay odd') | ||
elif choice == 37: | ||
print('pay 00') | ||
print('pay green') | ||
elif choice == 0: | ||
print(f'pay {choice}') | ||
print('pay green') | ||
|
||
|
||
if choice <= 18 and choice > 0: | ||
print('pay 1 to 18') | ||
elif choice > 18 and choice < 37: | ||
print('pay 19 to 36') | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
while True: | ||
number = int(input('type a number or 0 to end: ')) | ||
if number == 0: | ||
print(result) | ||
break | ||
else: | ||
new_number = int(input('type a number or 0 to end: ')) | ||
result = number + new_number | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import numpy as np | ||
|
||
for i in np.arange(4.95,29.95,5): | ||
discount = (round(i,2) * 60) / 100 | ||
discounted_price = round((round(i,2) - (round(i,2) * 60) / 100),2) | ||
print(f'The original price was {round(i,2)}, the discount is 60%, equal to {discount} and the new price is {discounted_price }') | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import math | ||
|
||
perimeter = 0 | ||
|
||
|
||
first_x = input('Enter the first x-coordinate: ') | ||
first_y = input('Enter the first y-coordinate: ') | ||
|
||
FIRST_X = float(first_x) | ||
FIRST_Y = float(first_y) | ||
|
||
|
||
x = FIRST_X | ||
y = FIRST_Y | ||
|
||
|
||
while True: | ||
next_x = input('Enter the next x-coordinate: ') | ||
if next_x == '': | ||
distance = math.sqrt((x - FIRST_X)**2 + (y - FIRST_Y)**2) | ||
perimeter = perimeter + distance | ||
break | ||
else: | ||
next_y = input('Enter the next y-coordinate: ') | ||
next_x = float(next_x) | ||
next_y = float(next_y) | ||
distance = math.sqrt((next_x - x)**2 + (next_y - y)**2) | ||
perimeter = perimeter + distance | ||
x = next_x | ||
y = next_y | ||
|
||
print(f'The perimeter of that polygon is {perimeter}') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
under_3 = 0 | ||
under_13 = 0 | ||
adult = 0 | ||
senior = 0 | ||
under_13_ticket = 14 | ||
adult_ticket = 23 | ||
senior_ticket = 18 | ||
|
||
while True: | ||
user_input = input('insert guest age or a blank line to quit: ') | ||
if user_input == '': | ||
break | ||
if int(user_input) < 3: | ||
under_3 += 1 | ||
elif 12 >= int(user_input) >= 3: | ||
under_13 += 1 | ||
elif int(user_input) >= 65: | ||
senior += 1 | ||
else: | ||
adult += 1 | ||
|
||
price_under_13 = int(under_13) * under_13_ticket | ||
price_adult = int(adult) * adult_ticket | ||
price_senior = int(senior) * senior_ticket | ||
total = '%.2f' % (price_under_13 + price_adult + price_senior) | ||
|
||
|
||
if under_3 and under_13 and adult and senior == 0: | ||
quit() | ||
else: | ||
print(f"Your group is composed by {under_3} children equal or under 2 years old , {under_13} equal or under 12 years old, {senior} over 65 and {adult} between 12 and 65. Total amount for tickets is {total} $") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
total = 0 | ||
|
||
while True: | ||
user_bit = input("Insert a 8 bit sequence or press enter to end: \n") | ||
if len(user_bit) == 8: | ||
for i in user_bit: | ||
i = int(i) | ||
total = total + i | ||
if total % 2 == 0: | ||
print(f"{user_bit} for even parity, parity bit should be 0") | ||
else: | ||
print(f"{user_bit} for even parity, parity bit should be 1") | ||
elif user_bit == '': | ||
break | ||
else: | ||
print('This is not a 8 bit sequence!') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
for i in range(0,101): | ||
if i % 3 == 0 and i % 5 != 0: | ||
print(f"{i} fizz!") | ||
elif i % 3 != 0 and i % 5 == 0: | ||
print(f'{i} buzz') | ||
elif i % 5 == 0 and i % 5 == 0: | ||
print(f"{i} fizz! buzz!") | ||
else: | ||
print(i) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend optimizing redundant code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
message = input('insert a message to encode or decode: ') | ||
number = int(input('insert a positive number to encode or negative to decode: ')) | ||
|
||
ALPHABET = 'abcdefghijklmnopqrstuvwxyz' | ||
new_message = '' | ||
|
||
|
||
for i in message: | ||
for e in ALPHABET: | ||
if e == i: | ||
index = ALPHABET.index(e) | ||
new_message += ALPHABET[index + number] | ||
|
||
print(new_message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend trying to use (input) numbers greater than 60. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
USER_INPUT = input('type a word: ') | ||
|
||
new_word = '' | ||
|
||
for i in reversed(USER_INPUT): | ||
new_word += i | ||
|
||
if new_word == USER_INPUT: | ||
print(f'{USER_INPUT} is a palyndrome') | ||
else: | ||
print(f'{USER_INPUT} isn\'t a palyndrome') | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
while True: | ||
user_input = int(input('type a postive number or a negative number or a 0 to end: ')) | ||
if user_input <= 0: | ||
break | ||
else: | ||
number = user_input | ||
sequence = str(number) | ||
while number != 1: | ||
if number % 2 == 0: | ||
number = number // 2 | ||
sequence += ' ' + str(number) | ||
else: | ||
number = number * 3 + 1 | ||
sequence += ' ' + str(number) | ||
print(sequence) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
number = int(input('type a number: ')) | ||
factor = 2 | ||
result = '' | ||
|
||
if number < 2: | ||
print('number must be grater or, at least, equal to 2') | ||
quit() | ||
|
||
|
||
while number >= factor: | ||
if number % factor == 0: | ||
number = number / factor | ||
result += ' ' + str(factor) | ||
else: | ||
factor += 1 | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
result = '' | ||
|
||
q = int(input('Type a number to convert in binary: ')) | ||
|
||
while q != 0: | ||
r = q % 2 | ||
result += str(r) | ||
q = q // 2 | ||
print(f'The binary value of the number is : {result}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import random | ||
|
||
high_number = random.choice(range(1,101)) | ||
|
||
update = 0 | ||
|
||
for i in range(1,100): | ||
number = random.choice(range(1,101)) | ||
if number > high_number: | ||
high_number = number | ||
print(f'{number} <== update') | ||
update += 1 | ||
else: | ||
print(number) | ||
|
||
print(f'The maximum value found was {high_number} and was updated {update} times ') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import random | ||
|
||
sequence = '' | ||
average = 0 | ||
|
||
for i in range(0,10): | ||
while sequence.count('TTT') == False and sequence.count('HHH') == False: | ||
value = random.randint(0,1) | ||
if value == 0: | ||
sequence += 'H' | ||
else: | ||
sequence += 'T' | ||
average += len(sequence) | ||
print(f'{sequence} ({len(sequence)} flips)') | ||
sequence = '' | ||
|
||
print(f'On average {average / 10} were needed.') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend re-implementing it without using numpy.