-
Notifications
You must be signed in to change notification settings - Fork 11
Week-4 #3
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
base: main
Are you sure you want to change the base?
Week-4 #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #dice percentage | ||
| import random | ||
|
|
||
| def percent(number): | ||
| dice=[0,0,0,0,0,0]# I created an array with 6 elements named dice and I filled this array with the value zero. | ||
| n=5000 | ||
| for i in range(n): | ||
| number=random.randint(1,6)# It will generate a random number with a value between 1 and 6 in a repetition 5000 times. | ||
| if number==1:#If the value is 1, increase the element 0 in the array by 1 | ||
| dice[0]+=1 | ||
| elif number==2:#It is the same for each numbers | ||
| dice[1]+=1 | ||
| elif number==3: | ||
| dice[2]+=1 | ||
| elif number==4: | ||
| dice[3]+=1 | ||
| elif number==5: | ||
| dice[4]+=1 | ||
| else: | ||
| dice[5]+=1 | ||
| percentage=dice[number-1]/n*100 #At the end of the repetition i calculated percentages with 2 decimal places. | ||
| return percentage # I wanted to return percentage | ||
|
|
||
|
|
||
| print("Percentage of throws of value","4","=",percent(4),"%") #I wrote it to the screen | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # a program which can calculate the greatest common divisor (GCD) of my inputs. | ||
| import math | ||
| def gcd(): | ||
| count=int(input("How many numbers do you want to enter: "))#I asked the number of the enters | ||
| numbers=[] #I opened a new list with the name numbers. | ||
|
|
||
| a=0 | ||
| while a<count:#it is going to turn until this formula | ||
| try: #I used try/except blocks to verify input entries and warn the user for Nan or non numerical inputs. | ||
| new=int(input("please enter new number")) | ||
| except Exception: | ||
| print("Please do not enter Nan or non numerical numbers.") | ||
| else: | ||
| numbers.append(new) | ||
| a+=1 | ||
|
|
||
| gcdr=math.gcd(numbers[0],numbers[1])#i tried to find gcd in numbers list for first two elements with gcd module. its name is gcdr | ||
| for i in range(2,len(numbers)):#then I started from third element in numbers list and i turned it with each elements. | ||
| gcdreal=int(math.gcd(gcdr,numbers[i]))#every turn it is going to be change. | ||
|
|
||
| return gcdreal #then i want to return gcdreal for the gcd numbers in numbers list | ||
|
|
||
| print("gcd is: ",gcd()) | ||
|
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. clear. sart degil ama while dongusu icinde kullandiginiz try/except blogu, bir ust satirdaki input kismina da eklenebilir. ilk input alirken de hatali giris olursa kod patlamadan devam edilmis olur. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #basic import 2 | ||
| import Rolldice #Then I created a new module called main.py | ||
|
|
||
| number=int(input("Enter repetition number: ")) #and i got an input from the user using "Enter repetition number: | ||
|
|
||
| print("The probability of",number,"is",Rolldice.percent(number)) #I wrote it to the screen. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #basic import | ||
| from Rolldice import percent # I called my (percent) function in Rooldice module. | ||
|
|
||
| n=input("How many times do you want to roll: ") #instead of 5000, I asked how many times do you want to roll | ||
|
|
||
| print(percent(4)) #I wrote only percentage to the screen. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #Python program to check the validity of a password (input from users) | ||
| import re | ||
| p= input("Input your password") | ||
| x = True | ||
| while x: | ||
| if (len(p)<6 or len(p)>12): #I asked all of the requirements | ||
| raise ValueError("The length of the password is not valid")#If there is a not valid enter,it will raise a error in each situation. | ||
| break | ||
| elif not re.search("[a-z]",p): | ||
| raise ValueError("There is no lower case in your password") | ||
| break | ||
| elif not re.search("[0-9]",p): | ||
| raise ValueError("There is no number in your password") | ||
| break | ||
| elif not re.search("[A-Z]",p): | ||
| raise ValueError("There is not a upper case in your password") | ||
| break | ||
| elif not re.search("[$#@]",p): | ||
| raise ValueError("There is not a special character in your password") | ||
| break | ||
|
|
||
| else: | ||
| print("Valid Password")#If all of the possibilities are true, it will write valid password to the screen. | ||
| x=False | ||
| break | ||
|
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. clear. ancak: sadece en sondaki break ifadesi kalsa yeterli bence. ValueError kisminda zaten dongu kiriliyor. diger break ler silinebilir. Ayrica While True: diyerek baslanabilir. yani x degiskenine atamaya gerek yok bence. |
||
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.
clear. ayrica yorum satirlari eklemis olmaniz cok iyi.