Python Forum

Full Version: Trouble with general code flow
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
As you can see by my crude coding I am a newbie.  I've gotten this far and know my objectives could be achieved by much better coding (last file asked to be open fails).  The objective is to put together a program based on a book about Christian counseling principles where-by through series of questions and answers received an analysis is achieved.  I had planned upon getting the question and answer part put together to go back inserting code to capture response and based on such response insert data into a client file in order to form the final analysis.
Can anyone offer help as to better code and ideas to achieve my final goal.  Thank-you
redacted


#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
"""
Created on Fri May 19 23:55:18 2017

@author: nisbet
"""

#def main():
#    Info.txt = raw_input("Info.txt: ")
#    infile = open(Info.txt, 'r')
#    data = infile.read()
#    print ("data")
#next
...
...
name = input('What is your name? ')
print('Hello ' + name)

Age = input('What is your age? ')
print('Your age is ' + Age)

num = input('Give me a PH number? ')
print('Is this right: ' + str(num))
import time
time.sleep(10)
with open("/home/nisbet/Heart_of_Man/Info.txt", "rt") as in_file:
   Info = in_file.read()

print(Info)
import time
time.sleep(15)
import sys
import os
with open("/home/nisbet/Heart_of_Man/forword.txt", "rt") as in_file:
   forword = in_file.read()
print(forword)
next
eval(input('Enter question number 1 through 10:'))
with open("/home/nisbet/Heart_of_Man/Question1.txt", "rt") as in_file:
       Question1 = in_file.read()
       if input == 1:
           Question1 = 1      
print(Question1)
import time
time.sleep(60)
next
eval(input('Does A B or C best discribe '))
print(name)
with open("/home/nisbet/Heart_of_Man/QuestionA.txt", "rt") as in_file:
       QuestionA = in_file.read()
       if input == A:
           QuestionA = A      
print(QuestionA)
Let's start with it's never a good idea to provide any personal information about yourself, including your email, on a public forum. This is a public forum, the questions and answers are for the benefit of all. Sending you an answer via email defeats the purpose of the forum.

As to your code, you only need to import your modules once and unless you have a really good reason, they should go at the top after line 7 and before line 9. "..." on line 15 and 16 serves no purpose. There is no "next" (lines 18 and 47) in Python. Since "num" is already a string (line 23) there really no need to hammer home the point in line 24, just print num. I'm not sure why you are using "eval" (lines 39 and 48), it you are expecting an integer, then use question_number = int(input("Enter a number ")) if you are expecting a letter, just use letter = input("Enter a letter ") .

These are a few of the problems. Tidy them up and come back should you have other problems. And read the Python 3.4 Documentation