Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4f1bee5

Browse files
Python Input-output and Functions
Opening and closing, reading and writing a file in python. Defining and calling a function as a factorial of an integer in python.
1 parent 1e208af commit 4f1bee5

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

‎Myfile.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I Love LetsUpgrade.Letsupgrade is the best platform for developers

‎Python Assignment-3.ipynb

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Q.Program in Python for Opening a File and Writing \" I Love LetsUpgrade\" And close it, and read it back again, and then append some data to it and close it."
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"file = open('Myfile.txt','w')\n",
17+
"file.write(\"I Love LetsUpgrade.\")\n",
18+
"file.close()\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"file = open('Myfile.txt','r')\n",
28+
"read_the_file= file.read()\n",
29+
"file.close()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 3,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"data": {
39+
"text/plain": [
40+
"'I Love LetsUpgrade.'"
41+
]
42+
},
43+
"execution_count": 3,
44+
"metadata": {},
45+
"output_type": "execute_result"
46+
}
47+
],
48+
"source": [
49+
"read_the_file"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 4,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"file = open('Myfile.txt','a')\n",
59+
"file.write('Letsupgrade is the best platform for developers')\n",
60+
"file.close()"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"metadata": {},
66+
"source": [
67+
"# Q.Function which can return a Factorial of any numbers as INT, given in the argument."
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 5,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"def factorial(num):\n",
77+
" if(num==1):\n",
78+
" return 1\n",
79+
" s= num*factorial(num-1)\n",
80+
" return s;"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 6,
86+
"metadata": {},
87+
"outputs": [
88+
{
89+
"data": {
90+
"text/plain": [
91+
"120"
92+
]
93+
},
94+
"execution_count": 6,
95+
"metadata": {},
96+
"output_type": "execute_result"
97+
}
98+
],
99+
"source": [
100+
"factorial(5)"
101+
]
102+
}
103+
],
104+
"metadata": {
105+
"kernelspec": {
106+
"display_name": "Python 3",
107+
"language": "python",
108+
"name": "python3"
109+
},
110+
"language_info": {
111+
"codemirror_mode": {
112+
"name": "ipython",
113+
"version": 3
114+
},
115+
"file_extension": ".py",
116+
"mimetype": "text/x-python",
117+
"name": "python",
118+
"nbconvert_exporter": "python",
119+
"pygments_lexer": "ipython3",
120+
"version": "3.8.5"
121+
}
122+
},
123+
"nbformat": 4,
124+
"nbformat_minor": 4
125+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /