Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Rolldice.py
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
Copy link

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.

23 changes: 23 additions & 0 deletions gcd1.py
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())
Copy link

Choose a reason for hiding this comment

The 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.

6 changes: 6 additions & 0 deletions main.py
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.
6 changes: 6 additions & 0 deletions my_dice.py
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.
25 changes: 25 additions & 0 deletions password1.py
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
Copy link

Choose a reason for hiding this comment

The 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.