Advertisement
wojtekw0703

Kalkulator z kombinacjami - python

Dec 11th, 2020
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. from flask import Flask
  2. from flask import render_template
  3. from flask import request
  4. from math import factorial
  5.  
  6. #Declaring the app
  7. app = Flask(__name__)
  8.  
  9. #Start an app route
  10. @app.route('/')
  11.  
  12. #Declaring main function
  13. def main():
  14.     return render_template('app.html')
  15.  
  16. #Form Submission Route
  17. @app.route('/send', methods=['POST'])
  18.  
  19.  
  20. def send(sum=sum):
  21.     if request.method == 'POST':
  22.         #Start pulling data from form input
  23.         n = request.form['n']
  24.         k = request.form['k']
  25.         operation = request.form['operation']
  26.         #Calculation
  27.         if operation == 'combinations-with-repetitions':
  28.             try:
  29.                 numerator = factorial(int(n) + int(k) - 1)
  30.                 denominator = factorial(int(k)) * factorial(int(n) - 1)
  31.                 sum = int(numerator) / int(denominator)
  32.                 return render_template('app.html', sum=int(sum))
  33.             except:
  34.                 return render_template('app.html', sum="Error has been occurred")
  35.         elif operation == 'combinations-without-repetitions':
  36.             try:
  37.                 numerator = factorial(int(n))
  38.                 denominator = factorial(int(k)) * factorial(int(n) - int(k))
  39.                 sum = int(numerator) / int(denominator)
  40.                 return render_template('app.html', sum=int(sum))
  41.             except:
  42.                 return render_template('app.html', sum="Error has been occurred")
  43.         else:
  44.             return render_template('app.html', sum="Blad")
  45.  
  46. if __name__ == ' __main__':
  47.     app.debug = True
  48.     app.run()
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement