File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ #converting pounds to kg
3+
4+ def pounds_to_kg (pounds ):
5+ return pounds * 0.453592
6+
7+ def feet_to_meters (feet ):
8+ return feet * 0.3048
9+
10+ def inches_to_meters (inches ):
11+ return inches * 0.0254
12+
13+ def yards_to_meters (yards ):
14+ return yards * 0.9144
15+
16+ def miles_to_meters (miles ):
17+ return miles * 1609.34
18+
19+ def miles_per_hour_to_ms (miles_per_hour ):
20+ return miles_per_hour * 0.44704
21+
22+ def celsius_to_kelvin (celsius ):
23+ return celsius + 273.15
24+
25+ def farenheit_to_kelvin (farenheit ):
26+ return ((farenheit - 32 )/ 1.8 ) + 273.15
Original file line number Diff line number Diff line change 1+ # The Collatz Conjecture is a famous math problem.
2+ # The conjecture is that after applying a sequence of one of two transformations,
3+ # every positive integer will eventually transform into 1.
4+ # The transformations are: divide by 2 if the number is even, multiply by 3 and add 1 if its odd.
5+ # You can see more about it here https://en.wikipedia.org/wiki/Collatz_conjecture
6+
7+ def collatz (initial_number ):
8+ num = initial_number
9+ print (f'Initial number is: { initial_number } ' )
10+ while num != 1 :
11+ print (num )
12+ if num % 2 == 0 :
13+ num = int (num / 2 )
14+ else :
15+ num = int (3 * num + 1 )
16+ else :
17+ print (num )
18+ print ('Finally!' )
Original file line number Diff line number Diff line change 1+ from random import randint , seed
2+
3+ # The randint(a,b) function return a pseudorandom number between a and b, including both.
4+ # The seed() function defines a new seed for pseudorandom numbers.
5+
6+ # This function defines a die roll. If no specific side is defined, it 'rolls' a six-sided die.
7+
8+ def die (sides = 6 ):
9+ seed ()
10+ result = randint (1 , sides )
11+ return result
12+
13+ # This function defines a dice roll.
14+ # If no specific side and number of dies are defined, it 'rolls' a six-sided die.
15+ #Returns a list of ints with the dice rolls.
16+
17+ def dice (number_of_die = 1 , sides = 6 ):
18+ rolls = []
19+ for roll in range (0 , number_of_die ):
20+ rolls .append (die (sides ))
21+ return rolls
You can’t perform that action at this time.
0 commit comments