Created
August 30, 2016 14:44
-
-
Save sonerb/2f51c10fec974c4ff8880a0add08f6e6 to your computer and use it in GitHub Desktop.
square_divde_round.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
import sys, os, time | |
from random import randint | |
is_path_ok = True | |
while(is_path_ok): | |
f_path = raw_input('Enter file path : ') | |
if os.path.exists(str(f_path)): | |
print('Path exists') | |
is_path_ok = False | |
else: | |
print('Path not exits') | |
f_name = raw_input('Enter file name : ') | |
full_file_path = str(f_path) + "/"+ str(f_name) | |
if os.path.exists(full_file_path): | |
file_name, file_ext = os.path.splitext(full_file_path) | |
os.rename(full_file_path, '{}_{}{}'.format(file_name,str(time.time()), file_ext)) | |
f_write = open(full_file_path, 'w') | |
number = raw_input('Enter decimal number : ') | |
try: | |
number = float(number) | |
except ValueError: | |
print('It\'s not a number') | |
number_sqrt = number ** 2 | |
print >> f_write, '{} squared is {}'.format(number,number_sqrt) | |
print('{} squared is {}'.format(number,number_sqrt)) | |
random_number = randint(0, 20) | |
number_diveded = float(number_sqrt / random_number) | |
print >> f_write, '{} diveded by {} is {}'.format(number_sqrt, random_number, number_diveded) | |
print('{} diveded by {} is {}'.format(number_sqrt, random_number, number_diveded)) | |
number_round = int(round(float(number_diveded))) | |
print >> f_write, 'Rounded output is {}'.format(number_round) | |
print('Rounded output is {}'.format(number_round)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment