diff --git a/Israa_week 1 b/Israa_week 1 new file mode 100644 index 0000000..296b4d3 --- /dev/null +++ b/Israa_week 1 @@ -0,0 +1,135 @@ + +#Question1 +for i in range(1,11): + print(i , end="\t") +print() + +#Question2 with for loop +number=int (input('enter the number: ')) +print('even numbers up to this number are: ') +for i in range(0,number+1): + if i%2==0: + print(i, end='\t') +print() + +#Question2 with while loop +number = int(input('enter the number: ')) +print ('even numbers up to this number are: ') +i=0 +while i<= number: + if i %2==0: + print(i, end ='\t') + i += 1 +print() + +#Question3 + +start=int(input('enter the start: ')) +end=int(input('enter the end: ')) +if start <= end: + for i in range(start,end+1): + print(i, end='\t') +else: + for i in range(end,start+1): + print(i,end='\t') +print() + + +#Question 4 Is this number odd or even +number= int(input('Enter the number?')) +if number %2==0: + print('This number is odd') +else: + print('This number is even') + +#Question 5 +number=int(input('Enter the number:')) +factorial=1 +if number > 0: + for i in range(1,number+1): + factorial *= i + print ('Factorial is :',factorial) +else: + print('The number should be positive') + + +#Question 6 +number=int(input('Enter the number: ')) +prime=0 +for i in range(2,number): + if number%i==0: + print('The number is not prime') + break + else: + prime=1 +if prime ==1: + print ('This number is prime') + + +#Question 7 + +limit=int(input('enter the limit: ')) +fib_sequence = [0, 1] # Initial Fibonacci numbers +while True: + next_number = fib_sequence[-1] + fib_sequence[-2] + if next_number > limit: + break + fib_sequence.append(next_number) +print(fib_sequence) + + +#Question 8 +word=input('enter the word: ') +word=word[::-1] +print(word) + +#Question9 +word=input('enter the word: ') +palindrome=True +for i in range( len(word)//+1): + if word[i]!=word[-(i+1)]: + palindrome=False + break +if palindrome: + print('This is palindrome word.') +else: + print('This is no palindrome word. ') + + +#Question10 +height=int(input('Enter the height in meters: ')) +weight=int(input('Enter the weight in kilograms: ')) +bmi=weight/(height**2) +if bmi<25: + print('Underweight') +elif 25<=bmi<30: + print ('Normal') +elif 30<=bmi<=40: + print('overweight') +else: + print('overweight') + +#Question11 +first_number=int(input('enter the first number: ')) +second_number=int(input('enter the second number: ')) +thrid_number=int(input('enter the third number: ')) + +if first_number>=second_number and first_number>=thrid_number: + print('The first number is the largest.') +if second_number>=first_number and second_number>=thrid_number: + print('The second number is the largest.') +if thrid_number>=first_number and thrid_number>=second_number: + print('The thrid number is the largest.') + + +#Question12 +for i in range(1,5): + midterm_grade=float(input('enter the midterm grade: ')) + final_grade=float(input('enter the final grade: ')) + average=0.4*midterm_grade + 0.6*final_grade + if average < 50: + print('Result:Failed') + print('average:',average) + else: + print('Result:Successful') + print('average:',average) \ No newline at end of file diff --git a/Mohammad_week 1 b/Mohammad_week 1 new file mode 100644 index 0000000..ffa1d51 --- /dev/null +++ b/Mohammad_week 1 @@ -0,0 +1,115 @@ +# Question 1# +######### +for i in range(1,11): + print(i) + +# Question 2 +######### +num = int(input("Enter thenumber: ")) +print("Even numbers to", num, "are:") +for i in range(0, num + 1, 2): + print(i) +print("Even numbers to", num, "are:") +i = 0 +while i <= num: + print(i) + i += 2 + +# Question 3 +########## +start = int(input("Enter the first number: ")) +end = int(input("Enter the last number: ")) +print("the range between", start, "and", end, "are:") +for num in range(start, end + 1): + print(num) + +# Question 4 +######## +num = int(input("Enter a number: ")) +if num % 2 == 0: + print(num, "is an even number.") +else: + print(num, "is an odd number.") + +# Question 5 +######### +num = int(input("Enter a positive integer: ")) +if num < 0: + print("Please enter a positive integer.") +else: + x = 1 + for i in range(2, num + 1): + x*= i +print(x) + +# Question 6 +######## +n = int(input("Enter a number: ")) +if n <= 1: + print("false") +for i in range(2, int(n ** 0.5) + 1): + if n % i == 0: + print("is not a prime number.") + else: + print(n, "is a prime number.") + +# Question 7 +######### +n = int(input("Enter a number: ")) +fib_seq =[] +a,b = 0,1 +while a<= n: + fib_seq.append(a) + a,b = b,a + b +print(fib_seq) + +# Question 8 +######## +word = input("Enter a word :") +rev_word = word[::-1] +print("rev_word = ", rev_word) + +# Question 9 +######### +word = input("Enter a word :") +if word == word[::-1]: + print("the word is a palindrome.") +else: + print("the word is not a palindrome.") + + # Question 10 + # ####### +weight = float(input("Enter your weight (kg): ")) +height = float(input("Enter your height (m): ")) + +x = weight / (height ** 2) + +if x < 25: + print("You are underweight.") +elif x < 30: + print("Your weight is normal.") +elif x <= 40: + print("You are overweight.") +else: + print("You are severely overweight.") + + # Question 11 + # ####### + numbers = input("Enter numbers separated by spaces: ").split() +largest_three = sorted(numbers, reverse=True)[:3] +print("The largest three numbers are:", largest_three) + + # Question 12 + # ####### +for i in range(1, 5): + print(f"Enter grades for Lesson {i}:") + + mid = float(input("Enter your midterm grade: ")) + fin = float(input("Enter your final grade: ")) + + average = (mid * 0.4) + (fin * 0.6) + + if average < 50: + print(f"Lesson {i}: FAILED\n") + else: + print(f"Lesson {i}: SUCCESSFUL\n") \ No newline at end of file diff --git a/asem_team_member_week_one.py b/asem_team_member_week_one.py new file mode 100644 index 0000000..3f5ff99 --- /dev/null +++ b/asem_team_member_week_one.py @@ -0,0 +1,194 @@ +#Question 1: Write a Python code that prints numbers from 1 to 10 on the screen. + +for i in range(1, 11): + print(i) + + +#Question 2: Take a number input from the user and write a Python program that prints even numbers up to this number on the screen. Do this first with 'for' and then with 'while' loops + +num = int(input("Enter a number: ")) + +for i in range(1, num +1): + if i % 2 == 0: + print(i) + +num = int(input("Enter a number: ")) + +i = 1 +while i <= num: + if i % 2 == 0: + print(i) + i += 1 + + + +#Question 3: Write a Python code that receives a start and end value from the user and prints all the numbers between these values ​​(including the end value) on the screen. + +start = int(input("Enter the start value: ")) +end = int(input("Enter the end value: ")) + +for i in range(start, end + 1): + print(i) + + +#Question 4: Get a number from the user and write a Python code that prints whether this number is odd or even. + +num = int(input("Enter a number: ")) + +if num % 2 == 0: + print("The number is even.") +else: + print("The number is odd.") + + + +##Question 5: Write a Python program that takes a positive integer input from the user and calculates its factorial. Factorial is the product of all positive integers between a number itself and 1. For example: if the user entered 5, the program should give the following output: Enter a number from the user: 5 Factorial: 120 + +num = int(input("Enter a positive integer: ")) + +factorial = 1 + +if num < 0: + print("Factorial is not defined for negative numbers.") +elif num == 0: + print("Factorial: 1") # by definition, 0! = 1 +else: + for i in range(1, num + 1): + factorial *= i + print("Factorial:", factorial) + + +##Question 6: Write a Python code that receives a number from the user and checks whether this number is prime. + +num = int(input("Enter a number: ")) + +if num <= 1: + print("Not a prime number.") +else: + is_prime = True + for i in range(2, int(num ** 0.5) + 1): + if num % i == 0: + is_prime = False + break + + if is_prime: + print("It is a prime number.") + else: + print("Not a prime number.") + + +##Question 7: How to create a loop that calculates the Fibonacci sequence and returns the result as a list containing numbers up to a certain limit? + +limit = int(input("Enter the limit for the Fibonacci sequence: ")) + +fibonacci = [0, 1] + +while True: + next_num = fibonacci[-1] + fibonacci[-2] + if next_num > limit: + break + fibonacci.append(next_num) + +print("Fibonacci sequence up to", limit, ":", fibonacci) + + +#Question 8: Write a Python code that takes a word from the user and prints the reverse of this word on the screen. + +word = input("Enter a word: ") + +reversed_word = "" + +for char in word: + reversed_word = char + reversed_word + +print("Reversed word:", reversed_word) + + +##Question 9: How to create a combination of loop and conditional statement that takes a word input from the user and checks whether that word is a palindrome (the same when read backwards)? + +word = input("Enter a word: ") + +reversed_word = "" + + +for char in word: + reversed_word = char + reversed_word + + +if word == reversed_word: + print("The word is a palindrome.") +else: + print("The word is not a palindrome.") + + + +##Question 10: Write the code that calculates the person's weight index and returns the result as underweight, overweight or overweight according to the index value. (You can look on the internet for the weight index calculation) To do this, ask the user for their weight and height measurements. weight index If it is below 25, it is weak, Between 25-30 is normal, If you are over 30-40, you are overweight. If you are over 40, you are overweight. + + +weight = float(input("Enter your weight in kilograms: ")) + + +height = float(input("Enter your height in meters: ")) + + +bmi = weight / (height ** 2) + +if bmi < 18.5: + category = "Underweight" +elif 18.5 <= bmi < 25: + category = "Normal weight" +elif 25 <= bmi < 30: + category = "Overweight" +elif 30 <= bmi < 35: + category = "Obesity Class I" +elif 35 <= bmi < 40: + category = "Obesity Class II" +else: + category = "Obesity Class III" + + +print(f"Your BMI is: {bmi:.2f}") +print(f"Category: {category}") + + + +##Question 11: How to write a Python program that finds the largest of three numbers entered by a user? + + + +num1 = float(input("Enter first number: ")) +num2 = float(input("Enter second number: ")) +num3 = float(input("Enter third number: ")) + + +if num1 >= num2 and num1 >= num3: + largest = num1 +elif num2 >= num1 and num2 >= num3: + largest = num2 +else: + largest = num3 + + +print("The largest number is:", largest) + + + +##Question 12: Get Midterm and Final grades from a student for any course. The sum of 40% of the midterm exam grade and 60% of the final grade will give the year-end average. If the average is below 50, "FAILED" will appear on the screen, and if it is 50 or above, "SUCCESSFUL" will be displayed on the screen. This printing process is 4 lessons. and the lessons will be written one after the other. + +for i in range(1, 5): + print(f"\nLesson {i}") + + midterm = float(input("Enter midterm grade: ")) + final = float(input("Enter final grade: ")) + + average = (midterm * 0.4) + (final * 0.6) + + print(f"Average: {average:.2f}") + + if average < 50: + print("Result: FAILED") + else: + print("Result: SUCCESSFUL") + + + diff --git a/hackerRank_assignments.py b/hackerRank_assignments.py new file mode 100644 index 0000000..4e68fa4 --- /dev/null +++ b/hackerRank_assignments.py @@ -0,0 +1,48 @@ +#1. Arithmetic Operators (https://www.hackerrank.com/challenges/python-arithmetic-operators/problem) +a = int(input()) +b = int(input()) + + +sum = a + b +sub = a - b +multi = a * b +print(sum) +print(sub) +print(multi) + +#2. Find the Runner-Up Score! (https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem) +n = int(input()) +arr = list(map(int, input().split())) +arr = tuple(arr) +max_score = max(arr) +arr = list(arr) + +while max_score in arr: + arr.remove(max_score) + +print(max(arr)) + + +#3. Print Function (https://www.hackerrank.com/challenges/python-print/problem) + +n = int(input()) +for i in range(1, n+1): + print(i, end="") + + +#4. Finding the percentage (https://www.hackerrank.com/challenges/finding-the-percentage/problem) +n = int(input()) +student_marks = {} + +for _ in range(n): + name, *line = input().split() + scores = list(map(float, line)) + student_marks[name] = scores + +query_name = input() + + +marks = student_marks[query_name] +average = sum(marks) / len(marks) + +print(f"{average:.2f}") \ No newline at end of file