Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
30a03528
Commit
30a03528
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
4aad9d2f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/GuessGame.ipynb
+73
-0
73 additions, 0 deletions
CodeExamples/GuessGame.ipynb
with
73 additions
and
0 deletions
CodeExamples/GuessGame.ipynb
0 → 100644
+
73
−
0
View file @
30a03528
{
"cells": [
{
"cell_type": "markdown",
"id": "a21a577a",
"metadata": {},
"source": [
"# Hello"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf5ba095",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
" Simple guess game that will loop until you get it right.\n",
" Be very careful that you follow the indentation here.\n",
"\"\"\"\n",
"\n",
"\n",
"import random\n",
"\n",
"def main():\n",
" correct = random.randint(1,9) # the randon correct value\n",
" print(\"Guess the number between 1 and 9\")\n",
"\n",
" number_of_tries = 0\n",
"\n",
" while True: # Start of infinite loop\n",
" guess = int(input(\"Have a guess (give an int) : \"))\n",
" number_of_tries += 1\n",
"\n",
" if guess == correct: # Test if the guess is correct\n",
" print(\"You guessed right\")\n",
" break # If correct break the loop\n",
" else:\n",
" print(\"You guessed wrong.... have another go\")\n",
" # End of loop\n",
"\n",
"\n",
" # This is after loop.\n",
" print(\"You took \" + str(number_of_tries) + \" attempt to guess right\")\n",
"\n",
"\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:a21a577a tags:
# Hello
%% Cell type:code id:cf5ba095 tags:
```
python
"""
Simple guess game that will loop until you get it right.
Be very careful that you follow the indentation here.
"""
import
random
def
main
():
correct
=
random
.
randint
(
1
,
9
)
# the randon correct value
print
(
"
Guess the number between 1 and 9
"
)
number_of_tries
=
0
while
True
:
# Start of infinite loop
guess
=
int
(
input
(
"
Have a guess (give an int) :
"
))
number_of_tries
+=
1
if
guess
==
correct
:
# Test if the guess is correct
print
(
"
You guessed right
"
)
break
# If correct break the loop
else
:
print
(
"
You guessed wrong.... have another go
"
)
# End of loop
# This is after loop.
print
(
"
You took
"
+
str
(
number_of_tries
)
+
"
attempt to guess right
"
)
main
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment