-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxt_random.py
More file actions
102 lines (74 loc) · 2.54 KB
/
Copy pathxt_random.py
File metadata and controls
102 lines (74 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Python exercises without following a particular topic.
Written on: January 19, 2025"""
# ## 1. Swapping Values
# # Swap the values of two variables without using a temporary variable.
# x = 5
# y = 10
# x, y = y, x
# print("x is equal to ",x)
# print("y is equal to ", y)
# ## 2. Area of a Circle
# # Calculate the area of a circle given its radius
# radius = float(input("Enter the radius of the circles: "))
# radius2 = radius * radius
# pi = 3.14159
# area = pi * radius * radius
# area1 = pi * radius2
# print("The area of the circle is:", area)
# print("The area of the circle is:", area1)
# ## 3. Temperature Conversion
# # Convert Celsius to Fahrenheit
# celsius = float(input("Enter temperature in Celsius: "))
# fahrenheit = (celsius * 9/5) + 32
# print("Temperature in Fahrenheit: ", fahrenheit)
# # Convert Fahrenheit to Celsius
# fahrenheit = float(input("Enter temperature in Fahrenheit: "))
# celsius = (fahrenheit - 32) * (5/9)
# print("Temperature in Celsius: ", celsius)
# ## 4. String Manipulation
# # Get a string from the user
# # Count the number of vowels in the string.
# string = input("Enter a string: ")
# vowels = "aeiouAEIOU"
# count = 0
# for char in string:
# if char in vowels:
# count += 1
# print("Your string has ", count, "number of vowels.")
# ## 5. Data Type Conversion
# # Get user input for age and height
# # Conver age to an integer and height to a float.
# age = int(input("Enter your age: "))
# height = float(input("Enter your height in meters: "))
# print("Your age is: ", age)
# print("Your height is: ", height)
##
# Write a function that takes a string as input and prints
# each character on a new line. Try "hello"
# Written on: January 22, 2025
# input_string = str(input("Please enter a string: "))
# def print_character(input_string):
# for letter in input_string:
# print(letter)
# print_character("Hello ")
# print_character(input_string)
"""Draw a Tree
from video: https://youtube.com/shorts/SGD7k-8i0Mw?si=ex3097d5O10B6AiV
Written on January 25, 2025"""
# *
# ***
# *****
# *******
# *********
# *********** 11
# *
# height = 6
# 6 * 2 = 12 - 1 = width of the tree
def tree(height):
length = height * 2 - 1
stars = 1 # starts with 1 star by default
for i in range(1,height+1): #
print(("*" * stars).center(length))
stars+=2 # increment 2 after printing each layer
print("*".center(length))
tree(6)