QrDroid

Category 1

Sponsor Ads
Domyhomework123.com - programming homework help. | Get your programming homework done with expert homework helper.

Trust Writemypaper123.com with your paper and you will never regret it.
Search Result Display Below



Sharecodepoint popular queries

Saturday, 1 December 2018

Python File Handling: Create, Append and Write : Program to create file & writing something in the file

In this program, we will learn how to create a file & how to write something in the file by taking the input from the user in python. U...
In this program, we will learn how to create a file & how to write something in the file by taking the input from the user in python. User will enter some data and if user wants to save the file then will press 'yes' or if not  then press 'no'.

Python File Handing : File handling is an important part of any application. Python has several functions for reading, creating, deleting, and updating files. In this program ,we are using open() file handing function. Add a parameter to the open() function: 

"a"  - Append - Append to the end of the file.
syntax : file = open(file_name,  'a')

"w" - Write -  Overwrite any existing content.
syntax : file = open(file_name, 'w')

"x"  - Create - Create a file, returns an error if the file does not exist.
syntax : file = open(file_name, 'x')

a, w and x are the methods of open() function.

If you are writing using 'w' method ,the old content  will be overwritten by the new content. If you don't want to overwrite the old content then use 'a' method (Append).

Syntax : 
file = open(file_name, 'w') # 'a' or 'x' or 'w'

file.write('content')

Python Code : ('w' Method Example)
print('welcome to sharecodepoint videos')
print('Write somthing about yourself')
aboutself = str(input())
choose = str(input('You want to save this file (yes/no)? '))
if choose == 'yes' or choose == 'Yes':
    print('Enter your file name : ')
    file_name = str(input())
    print('Your file is successfully saved !!')
else:
    print('Thank you for using our services')

files = open(file_name, 'w')
files.write(aboutself)

Output :
welcome to sharecodepoint videos 

Write somthing about yourself 

Hello dude !! Welcome to sharecodepoint videos 

You want to save this file (yes/no)? yes 

Enter your file name : 

file 

Your file is successfully saved !! 
Process finished with exit code 0

Video Tutorial :

Program to printing table by taking the number from user in phython

How to printing the table by taking value from user in python. We have displayed the multiplication table of variable num.  In this pr...
How to printing the table by taking value from user in python. We have displayed the multiplication table of variable num. 

In this program we taking the input from user and multiple the number (nums*num) num (1,2,3,4,5,6,7,8,9,10) , nums (user enter value). We are taking range(1,11) because by default start with 0 - 9 but we want to start 1.  Then we take the  range (1,11). 

Python Code :
num = 2
nums = int(input("Enter the any number "))
for num in range(1,11):
    mul = nums*num
    print(nums, '*', num, '=', mul)

Output  1:

Enter the any number 5
5
10
15
20
25
30
35
40
45
50

Process finished with exit code 0

Output 2 :

Enter the any number 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Process finished with exit code 0

How to taking the integer input value from user & print that value in phython

This example in on how to take the integer value from the user and print the value. I will show the simple and easy example to understand....
This example in on how to take the integer value from the user and print the value. I will show the simple and easy example to understand.

To taking input form the user we use input() function. Input function ask a user for some text input. If you want to taking string value from user then you use str(input()) & if you want taking input integer value from the user then use int(input()). 

Syntax : 
1. variable_name = int(input()) #syntax for taking input value

2. variable_name = str(input()) #syntax for taking string valure

3. variable_name = int(input('Enter the value ')) 
Python Code :
print('Enter the your phone number : ')
phone = int(input())
print("Your phone number : +91 -",phone)
Comment in python start with the #hastag like : #comment_line. Using #hastags you simply apply in single line but if you want add in the next line then you use again #. Hashtags comment not use for multiple line. only use single line comment.

Output :

Enter the your phone number : 
7011258995
Your phone number : +91 - 7011258995

Process finished with exit code 0

How to count the duplicate integer element in the list by taking value from user in python

What is list in python : list  like a array. A like contain & storage multiple data type at same time like : integer, string and more....
What is list in python : list  like a array. A like contain & storage multiple data type at same time like : integer, string and more. 

In this program i will you how to count the duplicate integer element by taking the value from user. Variable are store, num, find, number and dup. User can enter the radom number in the list. User can enter the element which element he want to find. store.count() to count the duplicate element.
store = []
num = int(input('How much integer element you want: '))
find = int(input('Which element you want to find: '))
print('Enter radon number :')
for i in range(1, num+1):
    print('Enter', i, 'number :')
    number = int(input())
    store.append(number)
    dup = store.count(find)

if dup == 0:
    print('\n No Duplicate Element find in the list')
else:
    print('\n',find,'is repeated at', dup, 'Times')

Output :

How much integer element you want: 5
Which element you want to find: 3
Enter radon number :
Enter 1 number :
2
Enter 2 number :
3
Enter 3 number :
4
Enter 4 number :
3
Enter 5 number :
3

 3 is repeated at 3 Times

Process finished with exit code 0

If you have any doubt regarding the example then leave your doubts in the comment box.

Monday, 19 November 2018

MTH401 - Discrete Mathematics end term exam question paper - lpu question paper

CSE211 - Computer Organization and Design end term exam question paper - Lpu Question Paper

CSE316 - Operating System End Term Exam Question Paper - Lpu Question Paper

 

Version 20.2.1 - 2016 - 2018 - © Sharecodepoint | Made in India. | Copyright Content