What is The Joy of Computing using Python?
Python is a popular programming language that is easy to learn and widely used for various applications such as web development, data science, and artificial intelligence. Learning Python can be a joyous experience as it allows you to create your own programs, automate tasks, and solve real-world problems.
Here are some tips to help you experience the joy of computing using Python:
- Start with the basics: Before diving into advanced topics, it is essential to learn the basics of Python such as syntax, data types, and control structures. This will help you build a strong foundation and make it easier to learn more advanced topics.
- Practice coding: The more you practice coding, the better you will get at it. You can start by writing simple programs and gradually move on to more complex ones. There are also many online resources such as coding challenges and competitions that can help you improve your coding skills.
- Learn from others: There is a vast community of Python developers who are always willing to help and share their knowledge. You can join online forums, attend meetups, and participate in online communities to learn from other developers.
- Use Python libraries: Python has a vast ecosystem of libraries and frameworks that can help you solve complex problems quickly. Some popular libraries include NumPy, Pandas, and Matplotlib for data science, Django and Flask for web development, and Pygame for game development.
- Have fun: Learning Python should be an enjoyable experience, so don't be afraid to experiment and have fun with it. You can build your own projects, such as a simple game, web app, or automation script, to make your learning experience more engaging and enjoyable.
Week 5: Programming Assignment 1
Due on 2023-03-02, 23:59 ISTwrite a Python program that finds the Greatest Common Divisor (GCD) of two numbers. Your program should take two input numbers from the user, and use a function named 'gcd' to find the GCD of those two numbers. Your program should then print out the GCD of the two numbers as the output.Solution :
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
num1 = int(input())
num2 = int(input())
result = gcd(num1, num2)
print(result)
write a Python program that finds the Greatest Common Divisor (GCD) of two numbers. Your program should take two input numbers from the user, and use a function named 'gcd' to find the GCD of those two numbers. Your program should then print out the GCD of the two numbers as the output.
Solution :
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
num1 = int(input())
num2 = int(input())
result = gcd(num1, num2)
print(result) |
Week 5: Programming Assignment 2
Due on 2023-03-02, 23:59 ISTWrite a Python program that calculates the dot product of two lists containing the same number of elements. The program should take two lists of integers as input from the user, and then call a function named dot_product to find the dot product of the two lists. The dot_product function should take two lists a and b as input, and should return the dot product of those two lists.
Your program should first prompt the user to enter the two lists of integers, which should be entered as strings separated by spaces. Your program should then convert the input strings into lists of integers. Your program should then call the dot_product function with the two lists as arguments, and store the resulting dot product in a variable named result. Finally, your program should print out the dot product of the two lists as the output.
You can assume that the two input lists will always contain the same number of elements. Your program should output an error message and exit gracefully if the two lists have different lengths.
In your implementation, you should define the dot_product function using a loop to calculate the dot product of the two input lists.
Solution :
def dot_product(a, b):
if len(a) != len(b):
print("Error: the two input lists have different lengths.")
return None
else:
result = 0
for i in range(len(a)):
result += a[i] * b[i]
return result
# Get input from user
a_str = input()
b_str = input()
# Convert input strings to lists of integers
a = [int(x) for x in a_str.split()]
b = [int(x) for x in b_str.split()]
# Calculate dot product
result = dot_product(a, b)
# Output result
if result is not None:
print(result)
Write a Python program that calculates the dot product of two lists containing the same number of elements. The program should take two lists of integers as input from the user, and then call a function named dot_product to find the dot product of the two lists. The dot_product function should take two lists a and b as input, and should return the dot product of those two lists.
Your program should first prompt the user to enter the two lists of integers, which should be entered as strings separated by spaces. Your program should then convert the input strings into lists of integers. Your program should then call the dot_product function with the two lists as arguments, and store the resulting dot product in a variable named result. Finally, your program should print out the dot product of the two lists as the output.
You can assume that the two input lists will always contain the same number of elements. Your program should output an error message and exit gracefully if the two lists have different lengths.
In your implementation, you should define the dot_product function using a loop to calculate the dot product of the two input lists.
In your implementation, you should define the dot_product function using a loop to calculate the dot product of the two input lists.
Solution :
def dot_product(a, b):
if len(a) != len(b):
print("Error: the two input lists have different lengths.")
return None
else:
result = 0
for i in range(len(a)):
result += a[i] * b[i]
return result
# Get input from user
a_str = input()
b_str = input()
# Convert input strings to lists of integers
a = [int(x) for x in a_str.split()]
b = [int(x) for x in b_str.split()]
# Calculate dot product
result = dot_product(a, b)
# Output result
if result is not None:
print(result) |
Week 5: Programming Assignment 3
Due on 2023-03-02, 23:59 IST
Write a Python function that takes a string s as input and returns the length of the largest streak of 0s in the string. For example, if the input string is "10001000110000000001", the function should return 6.
Input
The input string s is guaranteed to contain only 0s and 1s.
Output
The function should return an integer, representing the length of the largest streak of 0s in the input string.
Your program should also print the result.
Sample output
Your program should also print the result.
Sample output
Comments
Post a Comment